예제 #1
0
        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);
        }
예제 #2
0
        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();
            }
        }
예제 #3
0
        public void Run()
        {
            Assembly assembly = Assembly.Load("UserStorageServices, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f46a87b3d9a80705");

            var slaveServiceType = assembly.ExportedTypes
                                   .Where(t => t.GetCustomAttribute <MyApplicationServiceAttribute>() != null)
                                   .First(t => t.GetCustomAttribute <MyApplicationServiceAttribute>().ServiceMode == "UserStorageSlave");

            var slave = (UserStorageServiceSlave)Activator.CreateInstance(
                slaveServiceType,
                new UserMemoryRepository());

            Receiver     = slave.Receiver;
            SlaveService = new UserStorageServiceLog(slave);
        }
예제 #4
0
        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]
        }
예제 #5
0
        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);
        }
예제 #6
0
        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]
        }
예제 #7
0
        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]
        }
예제 #8
0
        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]
        }