예제 #1
0
        public void DeleteLibUser_ProvidingNull_ThrowException()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            ILibUserRepository libUserRepository = new LibUserRepository(context);

            var libUser = new LibUserTO {
                IdentityUserId = 23, InstrumentIds = new List <int> {
                    1
                }
            };

            //Act & Assert
            Assert.ThrowsException <ArgumentException>(() => libUserRepository.Delete(libUser));
        }
예제 #2
0
        public void DeleteLibUser_Successful()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

            using var context = new LibraryContext(options);
            ILibUserRepository libUserRepository = new LibUserRepository(context);

            var libUser = new LibUserTO {
                IdentityUserId = 23, InstrumentIds = new List <int> {
                    1
                }
            };
            var libUser2 = new LibUserTO {
                IdentityUserId = 4, InstrumentIds = new List <int> {
                    7, 4
                }
            };
            var libUser3 = new LibUserTO {
                IdentityUserId = 6, InstrumentIds = new List <int> {
                    2
                }
            };
            var addedLibUser  = libUserRepository.Add(libUser);
            var addedLibUser2 = libUserRepository.Add(libUser2);
            var addedLibUser3 = libUserRepository.Add(libUser3);

            context.SaveChanges();

            //Act
            var result = libUserRepository.Delete(addedLibUser);

            context.SaveChanges();
            //Assert
            Assert.AreEqual(2, libUserRepository.GetAll().Count());
        }