示例#1
0
        public async void AddMemberAsyncShouldThrowExcpetion()
        {
            // arrange
            var options = new DbContextOptionsBuilder <PH_DbContext>()
                          .UseInMemoryDatabase("AddMemberAsyncShouldThrowExcpetion")
                          .Options;

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

            Member newMember = new Member()
            {
                FirstName = "Rando",
                LastName  = "Random",
                Email     = "*****@*****.**",
                Username  = "******",
                Password  = "******",
                Phone     = "1231231234",
                //PointAvailable = 100
            };


            // act
            try
            {
                await repo.AddMemberAsync(newMember);

                await repo.AddMemberAsync(newMember);
            }
            catch (InvalidOperationException ex)
            {
                Assert.Equal("Duplicate info in unique Column", ex.Message);
            }
        }
示例#2
0
        public async void AddMemberAsyncShouldAdd()
        {
            // arrange
            var options = new DbContextOptionsBuilder <PH_DbContext>()
                          .UseInMemoryDatabase("AddMemberAsyncShouldAdd")
                          .Options;

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

            Member newMember = new Member()
            {
                FirstName = "Rando",
                LastName  = "Random",
                Email     = "*****@*****.**",
                Username  = "******",
                Password  = "******",
                Phone     = "1231231234",
                //PointAvailable = 100
            };

            // act
            await repo.AddMemberAsync(newMember);

            //actContext.SaveChanges();

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

            Assert.NotNull(member);
        }