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)); }
////[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)); }
// [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)); }
public void SearchByNameAndAge() { var user = new User() { FirstName = "Yan", LastName = "Big", Age = 20 }; var user1 = new User() { FirstName = "Yan", LastName = "Little", Age = 30 }; var slaveNode1 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveNode2 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveServiceCollection = new List <IUserStorageService>() { slaveNode1, slaveNode2 }; var storage = new UserStorageServiceMaster(new UserId(), new CompositeValidator(), slaveServiceCollection); var storageLog = new UserStorageServiceLog(storage); storageLog.Add(user); storageLog.Add(user1); Assert.AreEqual(storageLog.SearchByPredicate(u => u.FirstName == "Yan" && u.Age == 30).FirstOrDefault(), user1); }
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", 22)] public void GetFirstUserByFirstAndLastNameAndAge_FirstNameAlexLastNameBlack_FirstUserWithFirstNameAlexLastNameBlack( string first, string lastname, 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 = 111 }; UserStorageServiceMaster service = new UserStorageServiceMaster(new UserRepositoryWithState()); Assert.AreEqual(user1, service.GetFirstUserByFirstAndLastNameAndAge(first, lastname, age)); Assert.AreNotEqual(user4, service.GetFirstUserByFirstAndLastNameAndAge(first, lastname, age)); }
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 static void Main(string[] args) { // Loading configuration from the application configuration file. This configuration is not used yet. var serviceConfiguration = (ServiceConfiguration)System.Configuration.ConfigurationManager.GetSection("serviceConfiguration"); using (var host = new ServiceHost(MyDiagnostics.Create(serviceConfiguration))) { host.SmartOpen(); var slaveNode1 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveNode2 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveServiceCollection = new List <IUserStorageService>() { slaveNode1, slaveNode2 }; var storage = new UserStorageServiceMaster(new UserId(), new CompositeValidator(), slaveServiceCollection); var storageLog = new UserStorageServiceLog(storage); var client = new Client(storageLog); client.Run(); Console.WriteLine("Service \"{0}\" that is implemented by \"{1}\" class is available on \"{2}\" endpoint.", host.Description.Name, host.Description.ServiceType.FullName, host.BaseAddresses.First()); Console.WriteLine("Press <Enter> to stop the service."); Console.ReadLine(); host.Close(); } }
public void Remove_UserIdIsNotDefined_ExceptionThrown() { UserStorageService userStorageService = new UserStorageServiceMaster(new UserRepositoryWithState()); userStorageService.Remove(new User() { Id = Guid.Empty }); }
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 Remove_UserIsNotInStorage_ExceptionThrown() { UserStorageServiceSlave userStorageServiceSlave1 = new UserStorageServiceSlave(new UserRepositoryWithState()); UserStorageServiceSlave userStorageServiceSlave2 = new UserStorageServiceSlave(new UserRepositoryWithState()); UserStorageServiceMaster userStorageServiceMaster = new UserStorageServiceMaster(new UserRepositoryWithState(), new List <UserStorageServiceSlave>(new[] { userStorageServiceSlave1, userStorageServiceSlave2 })); userStorageServiceMaster.Remove(new User() { Id = Guid.NewGuid(), FirstName = "alex", LastName = "black", Age = 24 }); }
public void Remove_InvalidPredicate_ExceptionThrown(Predicate <User> predicate) { // Arrange var userStorageService = new UserStorageServiceMaster( new UserMemoryRepository(), Enumerable.Empty <INotificationReceiver>()); InitUserStoreageService(userStorageService); // Act userStorageService.Remove(predicate); }
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 int Search_ExistingUser_FindSomeUsers(Predicate <User> predicate) { // Arrange var userStorageService = new UserStorageServiceMaster( new UserMemoryRepository(), Enumerable.Empty <INotificationReceiver>()); InitUserStoreageService(userStorageService); // Act var users = userStorageService.Search(predicate); // Assert return(users.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_ExistingUser_RemoveOneUser(User user) { // Arrange var userStorageService = new UserStorageServiceMaster( new UserMemoryRepository(), Enumerable.Empty <INotificationReceiver>()); InitUserStoreageService(userStorageService); int oldUserCount = userStorageService.Count; // Act userStorageService.Remove((u) => u == user); // Assert Assert.AreEqual(oldUserCount - 1, userStorageService.Count); }
public void Search_NotExistingUser_FindNoUsers() { // Arrange var userStorageService = new UserStorageServiceMaster( new UserMemoryRepository(), Enumerable.Empty <INotificationReceiver>()); InitUserStoreageService(userStorageService); Predicate <User> predicate = (u) => u.FirstName == "NotExistingName"; // Act var users = userStorageService.Search(predicate); // Assert Assert.AreEqual(0, users.Count()); }
public void Add_UserAgeLessThen10_ExceptionThrown() { // Arrange var userStorageService = new UserStorageServiceMaster(new UserRepositoryWithState()); var s = new UserStorageLog(userStorageService); // Act s.Add(new User { FirstName = "Evgeny", LastName = "Ermolovich", Age = 4 }); // Assert - [ExpectedException] }
public void Add_NullAsUserArgument_ExceptionThrown() { // Arrange var slaveNode1 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveNode2 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveServiceCollection = new List <IUserStorageService>() { slaveNode1, slaveNode2 }; var storage = new UserStorageServiceMaster(new UserId(), new CompositeValidator(), slaveServiceCollection); var storageLog = new UserStorageServiceLog(storage); // Act storageLog.Add(null); // Assert - [ExpectedException] }
public void SearchByName_Exception2() { var slaveNode1 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveNode2 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveServiceCollection = new List <IUserStorageService>() { slaveNode1, slaveNode2 }; var storage = new UserStorageServiceMaster(new UserId(), new CompositeValidator(), slaveServiceCollection); var storageLog = new UserStorageServiceLog(storage); var user = new User() { FirstName = "Yan", Age = -20 }; storageLog.Add(user); Assert.AreEqual(storageLog.SearchByAge(user.Age).FirstOrDefault(), user); }
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); }
public void Add_UserLastNameConsistsOfWhiteSpaces_ExceptionThrown() { //// Arrange var slaveNode1 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveNode2 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveServiceCollection = new List <IUserStorageService>() { slaveNode1, slaveNode2 }; var storage = new UserStorageServiceMaster(new UserId(), new CompositeValidator(), slaveServiceCollection); var storageLog = new UserStorageServiceLog(storage); //// Act storageLog.Add(new User { LastName = " " }); //// Assert - [ExpectedException] }
public void AddUsersToMaster_SameUsersAppearInSlaves() { // Arrange var slaveServices = new[] { new UserStorageServiceSlave(new UserMemoryRepository()), new UserStorageServiceSlave(new UserMemoryRepository()), }; var receivers = slaveServices.Select(s => s.Receiver); var masterService = new UserStorageServiceMaster(new UserMemoryRepository(), receivers); // Act InitUserStoreageService(masterService); var slaveUsers0 = slaveServices[0].Search((u) => true); var slaveUsers1 = slaveServices[1].Search((u) => true); // Assert AssertAreEqual(Users, slaveUsers0, CompareUsers); AssertAreEqual(Users, slaveUsers1, CompareUsers); }
public void Remove_WithoutArguments_NothingHappen() { // Arrange var slaveNode1 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveNode2 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveServiceCollection = new List <IUserStorageService>() { slaveNode1, slaveNode2 }; var storage = new UserStorageServiceMaster(new UserId(), new CompositeValidator(), slaveServiceCollection); var storageLog = new UserStorageServiceLog(storage); // Act storageLog.Add(new User { FirstName = "Alex", LastName = "Usov", Age = 21, }); // Assert - [ExpectedException] }
public void Add_UserAgeIsNegative_ExceptionThrown() { //// Arrange var slaveNode1 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveNode2 = new UserStorageServiceSlave(new UserId(), new CompositeValidator()); var slaveServiceCollection = new List <IUserStorageService>() { slaveNode1, slaveNode2 }; var storage = new UserStorageServiceMaster(new UserId(), new CompositeValidator(), slaveServiceCollection); var storageLog = new UserStorageServiceLog(storage); ////Act storageLog.Add(new User { FirstName = "Alex", LastName = "Johnson", Age = -1 }); //// Assert - [ExpectedException] }
public void GetFirstUserByName_Null_ArgumentNullException() { UserStorageServiceMaster service = new UserStorageServiceMaster(new UserRepositoryWithState()); Assert.Catch <ArgumentNullException>(() => service.GetFirstUserByName(null)); }