Пример #1
0
        public async void AddProfessionalAsyncShouldThrowExcpetion()
        {
            // arrange
            var options = new DbContextOptionsBuilder <PH_DbContext>()
                          .UseInMemoryDatabase("AddProfessionalAsyncShouldThrowExcpetion")
                          .Options;

            Professional professional = new Professional()
            {
                Email     = "*****@*****.**",
                FirstName = "Rando",
                LastName  = "Random",
                Username  = "******",
                Password  = "******",
                Phone     = "1231231234",
                //Profile_Pic = p.User.Profile_Pic,
                //PointAvailable = p.AccInfo.PointAvailable,
                Category = "Math"
            };

            Professional professional2 = new Professional()
            {
                Email     = "*****@*****.**",
                FirstName = "Randwo",
                LastName  = "Randowm",
                Username  = "******",
                Password  = "******",
                Phone     = "w",
                //Profile_Pic = p.User.Profile_Pic,
                //PointAvailable = p.AccInfo.PointAvailable,
                Category = "English"
            };

            using (var actContext = new PH_DbContext(options))
            {
                var repo = new UserRepo(actContext);

                // act
                try {
                    await repo.AddProfessionalAsync(professional);

                    await repo.AddProfessionalAsync(professional);
                }
                catch (InvalidOperationException ex)
                {
                    Assert.Equal("Duplicate info in unique Column", ex.Message);
                }
                //   Exception ex = await Assert.ThrowsAsync<InvalidOperationException>(() => repo.AddProfessionalAsync(professional));

                // Assert.Equal("Duplicate info in unique Column", ex.Message);
            }
        }
Пример #2
0
        public async void AddProfessionalAsyncShouldAdd()
        {
            // arrange
            var options = new DbContextOptionsBuilder <PH_DbContext>()
                          .UseInMemoryDatabase("AddProfessionalAsyncShouldAdd")
                          .Options;

            using var actContext = new PH_DbContext(options);
            var repo = new UserRepo(actContext);

            Professional professional = new Professional()
            {
                Email     = "*****@*****.**",
                FirstName = "Rando",
                LastName  = "Random",
                Username  = "******",
                Password  = "******",
                Phone     = "1231231234",
                //Profile_Pic = p.User.Profile_Pic,
                //PointAvailable = p.AccInfo.PointAvailable,
                Category = "Math"
            };

            // act
            await repo.AddProfessionalAsync(professional);

            //actContext.SaveChanges();

            // assert
            using var assertContext = new PH_DbContext(options);
            var member = assertContext.Members.Select(m => professional);

            Assert.NotNull(member);
        }