コード例 #1
0
        public void IsReturnedTypeUserInfo()
        {
            mocker.Setup(m => m.ReadUsers("test"))
            .Returns(new List <UserAdapterProxy>()
            {
                new UserAdapterProxy()
                {
                    Name = "Kolya",
                    Age  = 18,
                    City = "New-York"
                },
                new UserAdapterProxy()
                {
                    Name = "Valik",
                    Age  = 23,
                    City = "Washington"
                }
            });

            UserManagerAdapter userManagerAdapter = new UserManagerAdapter(mocker.Object, "test");

            var result = userManagerAdapter.GetAll();

            var expected = new List <UserInfoAdapterProxy>()
            {
                new UserInfoAdapterProxy()
                {
                    Age  = 18,
                    Name = "Kolya"
                },

                new UserInfoAdapterProxy()
                {
                    Age  = 23,
                    Name = "Valik"
                }
            };

            for (int i = 0; i < result.Count - 1; i++)
            {
                Assert.Equal(expected[i].Age, result[i].Age);
                Assert.Equal(expected[i].Name, result[i].Name);
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            string source = @"C:\Users\msemeniu\Desktop\UserAdapter.txt";
            UsersFileReaderProxy proxy           = new UsersFileReaderProxy();
            UsersInfoFileReader  fileReader      = new UsersInfoFileReader();
            UsersFileReader      usersFileReader = new UsersFileReader();
            UserManagerAdapter   userManager     = new UserManagerAdapter(usersFileReader, source);
            UserManagerAdapter   userManager2    = new UserManagerAdapter(proxy, source);
            var users  = userManager.GetAll();
            var users2 = userManager2.GetAll();

            //var testUser = new UserInfoAdapterProxy()
            //{
            //    Age = 20,
            //    Name="Petika"
            //};
            //userManager2.AddUser(testUser);

            foreach (var user in users2)
            {
                Console.WriteLine(user.Age + " " + user.Name);
            }

            Console.ReadKey();

            /////////////////////////////////////////////////////////////////////////

            //string source2 = @"C:\Users\msemeniu\Desktop\UsersInfo.txt";
            //FileFactory fileFactory = new FileFactory(source2);
            //UserManagerFactory userManagerFactory = new UserManagerFactory(fileFactory);
            //var userList = userManagerFactory.ByCity("Beijing");
            //foreach (var user in userList)
            //{
            //    Console.WriteLine($"{user.Name},{user.Age},{user.City}");
            //}
            ////userManagerFactory.Add("Vasya", 18, "Beijing");
            //userManagerFactory.Delete(new Guid("8ff8cec0-5930-47f4-913a-17bb613739bc"));

            //Console.ReadKey();

            /////////////////////////////////////////////////////////////////////////////////

            string             jsonSource      = @"C:\Users\msemeniu\Desktop\UsersJson.txt";
            JSONFactory        jsonFactory     = new JSONFactory(jsonSource);
            UserManagerFactory userManagerJson = new UserManagerFactory(jsonFactory);
            //userManagerJson.Add("Vasya", 18, "Beijing");
            //userManagerJson.Add("Kolya", 20, "Tokyo");
            var usersJson = userManagerJson.ByCity("Tokyo");

            foreach (var user in usersJson)
            {
                Console.WriteLine(user.Name + " " + user.Age + " " + user.City);
            }
            userManagerJson.Delete(new Guid("2f638806-9fcf-49f3-ab88-247ff481955d"));
            /////
            Console.ReadLine();

            OrdersReader             reader        = new OrdersReader(@"C:\Users\msemeniu\Desktop\StrategiFile.txt");
            CostSumAnalyticsStrategy strategy      = new CostSumAnalyticsStrategy();
            OrdersManager            ordersManager = new OrdersManager(strategy);

            ordersManager.Import(@"C:\Users\msemeniu\Desktop\StrategiFile.txt");
            ordersManager.PrintAnalitycs();

            Console.WriteLine("///////////////////////////////////////");

            AnalyticsStrategy avgStrategy      = new AverageAnalyticStrategy();
            OrdersManager     ordersManagerAvg = new OrdersManager(avgStrategy);

            ordersManagerAvg.Import(@"C:\Users\msemeniu\Desktop\StrategiFile.txt");
            ordersManagerAvg.PrintAnalitycs();


            Console.ReadKey();
        }