public void GetFirstUserByName_FirstNameJohn_Null(string name) { User user1 = new User() { FirstName = "Alex", LastName = "Blck", Age = 22 }; User user2 = new User() { FirstName = "Mike", LastName = "red", Age = 123 }; User user3 = new User() { FirstName = "Sue", LastName = "gen", Age = 42 }; User user4 = new User() { FirstName = "Alex", LastName = "Black", Age = 111 }; UserStorageServiceMaster service = new UserStorageServiceMaster(new UserRepositoryWithState()); service.Add(user1); service.Add(user2); service.Add(user3); service.Add(user4); Assert.AreEqual(null, service.GetFirstUserByName(name)); }
public void GetAllUsersByName_FirstNameAlex_AllUsersWithNameAlex(string name) { User user1 = new User() { FirstName = "Alex", LastName = "Blck", Age = 22 }; User user2 = new User() { FirstName = "Mike", LastName = "red", Age = 123 }; User user3 = new User() { FirstName = "Sue", LastName = "gen", Age = 42 }; User user4 = new User() { FirstName = "Alex", LastName = "Black", Age = 111 }; UserStorageServiceMaster master = new UserStorageServiceMaster(new UserRepositoryWithState(), new List <UserStorageServiceSlave>(new[] { new UserStorageServiceSlave(new UserRepositoryWithState()), new UserStorageServiceSlave(new UserRepositoryWithState()) })); master.Add(user1); master.Add(user2); master.Add(user3); master.Add(user4); Assert.AreEqual(new[] { user1, user4 }, master.GetAllUsersByName(name).Take(2)); }
public void GetAlltUsersByFirstAndLastNameAndAge_FirstNameAlexLastNameBlack_FirstUserWithFirstNameAlexLastNameBlack( string first, string last, int age) { User user1 = new User() { FirstName = "Alex", LastName = "Black", Age = 22 }; User user2 = new User() { FirstName = "Mike", LastName = "red", Age = 123 }; User user3 = new User() { FirstName = "Sue", LastName = "gen", Age = 42 }; User user4 = new User() { FirstName = "Alex", LastName = "Black", Age = 22 }; UserStorageServiceMaster master = new UserStorageServiceMaster(new UserRepositoryWithState(), new List <UserStorageServiceSlave>(new[] { new UserStorageServiceSlave(new UserRepositoryWithState()), new UserStorageServiceSlave(new UserRepositoryWithState()) })); master.Add(user1); master.Add(user2); master.Add(user3); master.Add(user4); Assert.AreEqual(new[] { user1, user4 }, master.GetAllUsersByFirstAndLastNameAndAge(first, last, age).Take(2)); }
// [TestCase("Alex", "Black")] public void GetFirstUserByFirstAndLastName_FirstNameAlexLastNameBlack_FirstUserWithFirstNameAlexLastNameBlack( string first, string last) { User user1 = new User() { FirstName = "Alex", LastName = "Black", Age = 22 }; User user2 = new User() { FirstName = "Mike", LastName = "red", Age = 123 }; User user3 = new User() { FirstName = "Sue", LastName = "gen", Age = 42 }; User user4 = new User() { FirstName = "Alex", LastName = "Black", Age = 111 }; UserStorageServiceMaster service = new UserStorageServiceMaster(null); service.Add(user1); service.Add(user2); service.Add(user3); service.Add(user4); Assert.AreEqual(user1, service.GetAllUsersByFirstAndLastName(first, last)); Assert.AreNotEqual(user4, service.GetAllUsersByFirstAndLastName(first, last)); }
////[TestCase("Black", 22)] public void GetFirstUserByLastNameAndAge_FirstNameAlexLastNameBlack_FirstUserWithFirstNameAlexLastNameBlack( string first, int age) { User user1 = new User() { FirstName = "Alex", LastName = "Black", Age = 22 }; User user2 = new User() { FirstName = "Mike", LastName = "red", Age = 123 }; User user3 = new User() { FirstName = "Sue", LastName = "Black", Age = 42 }; User user4 = new User() { FirstName = "Alex", LastName = "Black", Age = 22 }; UserStorageServiceMaster master = new UserStorageServiceMaster(new UserRepositoryWithState(), new List <UserStorageServiceSlave>(new[] { new UserStorageServiceSlave(new UserRepositoryWithState()), new UserStorageServiceSlave(new UserRepositoryWithState()) })); master.Add(user1); master.Add(user2); master.Add(user3); master.Add(user4); Assert.AreEqual(user1, master.GetFirstUserByLastNameAndAge(first, age)); /// Assert.AreNotEqual(user4, master.GetFirstUserByLastNameAndAge(first, age)); }
public void Add_NullAsUserArgument_ExceptionThrown() { // Arrange var userStorageService = new UserStorageServiceMaster(null); // Act userStorageService.Add(null); // Assert - [ExpectedException] }
public void Add_InvalidUser_ExceptionThrown(User user) { // Arrange var userStorageService = new UserStorageServiceMaster( new UserMemoryRepository(), Enumerable.Empty <INotificationReceiver>()); // Act userStorageService.Add(user); }
public void Add_UserFirstNameIsNull_ExceptionThrown() { // Arrange var userStorageService = new UserStorageServiceMaster(new UserRepositoryWithState()); // Act userStorageService.Add(new User { FirstName = null }); // Assert - [ExpectedException] }
public void Add_ValidUser_StorageCountIs1() { // Arrange var userStorageService = new UserStorageServiceMaster( new UserMemoryRepository(), Enumerable.Empty <INotificationReceiver>()); var user = GetValidUser(); // Act userStorageService.Add(user); // Assert Assert.AreEqual(1, userStorageService.Count); }
public void MasterMethodAdd_AnyUser_UserAddedToSlaveNodes() { User user = new User() { FirstName = "Alex", LastName = "Black", Age = 22 }; UserStorageServiceSlave slaveService1 = new UserStorageServiceSlave(new UserRepositoryWithState()); UserStorageServiceSlave slaveService2 = new UserStorageServiceSlave(new UserRepositoryWithState()); UserStorageServiceMaster masterService = new UserStorageServiceMaster(new UserRepositoryWithState(), new List <UserStorageServiceSlave>(new[] { slaveService1, slaveService2 })); masterService.Add(user); Assert.AreEqual(1, slaveService1.Count); Assert.AreEqual(1, slaveService2.Count); }
public void Add_UserAgeGreaterThen100_ExceptionThrown() { // Arrange var userStorageService = new UserStorageServiceMaster(new UserRepositoryWithState()); // Act userStorageService.Add(new User { FirstName = "Alex", LastName = "Ermolovich", Age = 101 }); // Assert - [ExpectedException] }
public void Remove_User_UserIsRemoved() { User user = new User() { Id = Guid.NewGuid(), FirstName = "Alex", LastName = "Black", Age = 25 }; UserStorageServiceMaster userStorageService = new UserStorageServiceMaster(new UserRepositoryWithState()); UserStorageServiceSlave slave1 = new UserStorageServiceSlave(new UserRepositoryWithState()); UserStorageServiceSlave slave2 = new UserStorageServiceSlave(new UserRepositoryWithState()); userStorageService.AddSubscriber(slave1); userStorageService.AddSubscriber(slave2); userStorageService.Add(user); userStorageService.Remove(user); Assert.AreEqual(0, slave2.Count); Assert.AreEqual(0, slave1.Count); }
/// <summary> /// Runs a sequence of actions on an instance of the <see cref="UserStorageService"/> class. /// </summary> public void Run() { var filePath = ConfigurationManager.AppSettings["FilePath"]; repositoryManager.Start(); UserStorageServiceMaster m = new UserStorageServiceMaster((IUserRepository)repositoryManager, new List <UserStorageServiceSlave>(new[] { new UserStorageServiceSlave(new UserRepositoryWithState()), new UserStorageServiceSlave(new UserRepositoryWithState()) })); m.AddSubscriber(new UserStorageServiceSlave((IUserRepository)repositoryManager)); m.Add(new User() { FirstName = "a", LastName = "b", Age = 55 }); repositoryManager.Stop(); ///_userStorageService.Remove(null); ///_userStorageService.Search(null); }