コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }
コード例 #4
0
        // [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));
        }
コード例 #5
0
        ////[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));
        }
コード例 #6
0
        public void Add_NullAsUserArgument_ExceptionThrown()
        {
            // Arrange
            var userStorageService = new UserStorageServiceMaster(null);

            // Act
            userStorageService.Add(null);

            // Assert - [ExpectedException]
        }
コード例 #7
0
        public void Add_InvalidUser_ExceptionThrown(User user)
        {
            // Arrange
            var userStorageService = new UserStorageServiceMaster(
                new UserMemoryRepository(),
                Enumerable.Empty <INotificationReceiver>());

            // Act
            userStorageService.Add(user);
        }
コード例 #8
0
        public void Add_UserFirstNameIsNull_ExceptionThrown()
        {
            // Arrange
            var userStorageService = new UserStorageServiceMaster(new UserRepositoryWithState());

            // Act
            userStorageService.Add(new User
            {
                FirstName = null
            });

            // Assert - [ExpectedException]
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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]
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        /// <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);
        }