Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

async dbContext test #1188


User avatar
0
drsmallbone created

Hello!

First of all love your work!

I have just decided to create a new project with the latest templates (Amazing notifications/signalr stuff) and for the first time I decided to go TDD. I have not done much testing before and my async mental strength is lacking. However I spotted this and I am not sure it is a bug or I am not understanding the logic.

[Fact]
        public async Task CreateUser_Test()
        {
            //Act
            await _userAppService.CreateUser(
                new CreateUserInput
                {
                    EmailAddress = "[email protected]",
                    IsActive = true,
                    Name = "John",
                    Surname = "Nash",
                    Password = "123qwe",
                    UserName = "john.nash"
                });

            await UsingDbContextAsync(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.naash");
                johnNashUser.ShouldNotBeNull();
            });
        }

        [Fact]
        public async Task CreateUser_Without_Async_Context_Test()
        {
            //Act
            await _userAppService.CreateUser(
                new CreateUserInput
                {
                    EmailAddress = "[email protected]",
                    IsActive = true,
                    Name = "John",
                    Surname = "Nash",
                    Password = "123qwe",
                    UserName = "john.nash"
                });

            await UsingDbContext(async context =>
            {
                var johnNashUser = await context.Users.FirstOrDefaultAsync(u => u.UserName == "john.naash");
                johnNashUser.ShouldNotBeNull();
            });
        }

I have set it so they will both fail as the username should not match however the default test with UsingDbContextAsync will return a NULL but will not fail the test.

:? :?

If I correct the Username they will both pass.

Thanks


No answer yet!