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

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

            //Act
            var libUser = new LibUserTO {
                IdentityUserId = 23, InstrumentIds = new List <int> {
                    1
                }
            };
            var libUser2 = new LibUserTO {
                Id = 2, IdentityUserId = 23, InstrumentIds = new List <int> {
                    1
                }
            };
            var addedLibUser  = libUserRepository.Add(libUser);
            var addedLibUser2 = libUserRepository.Add(libUser2);

            context.SaveChanges();

            //Assert
            Assert.AreEqual(1, libUserRepository.GetAll().Count());
        }
예제 #2
0
        public void AddLibUser_Successful()
        {
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

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

            //Act
            var libUser = new LibUserTO {
                IdentityUserId = 23, InstrumentIds = new List <int> {
                    1
                }
            };
            var result   = libUserRepository.Add(libUser);
            var libUser2 = new LibUserTO {
                IdentityUserId = 2, InstrumentIds = new List <int> {
                    1
                }
            };
            var result2 = libUserRepository.Add(libUser2);

            context.SaveChanges();

            //Assert
            Assert.IsNotNull(result);
            Assert.AreEqual(result.InstrumentIds.First(), 1);
            Assert.AreEqual(result.IdentityUserId, 23);
        }
예제 #3
0
        public void UpdateLibUser_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 = new List <int> {
                4, 2
            };

            addedLibUser.InstrumentIds = new List <int> {
                4, 2
            };
            var test = libUserRepository.Update(addedLibUser);

            context.SaveChanges();

            //Assert
            Assert.AreEqual(3, libUserRepository.GetAll().Count());
            CollectionAssert.AreEqual(new List <int> {
                4, 2
            }, test.InstrumentIds);
        }
예제 #4
0
        public void GetLibUsertById_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.GetById(1);
            var result2 = libUserRepository.GetById(2);
            var result3 = libUserRepository.GetById(3);

            //Assert
            Assert.AreEqual(23, result.IdentityUserId);
            Assert.AreEqual(4, result2.IdentityUserId);
            Assert.AreEqual(6, result3.IdentityUserId);
        }
예제 #5
0
        public void AddLibUser_AddNull_ThrowException()
        {
            //Arrange
            var options = new DbContextOptionsBuilder <LibraryContext>()
                          .UseInMemoryDatabase(databaseName: MethodBase.GetCurrentMethod().Name)
                          .Options;

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

            //Act & Assert
            Assert.ThrowsException <ArgumentNullException>(() => libUserRepository.Add(null));
        }