Esempio n. 1
0
        public void CreatePhoneOrderEmptyInput()
        {
            PhoneOrderService phoneOrderService           = new PhoneOrderService();
            PhoneOrderEntity  phoneOrderEntityFromFactory = new PhoneOrderEntity();
            MemoryStream      ms = new MemoryStream();
            StreamWriter      sw = new StreamWriter(ms);
            String            response;

            Mock <PhoneOrderRepository> mockPhoneOrderRepository = mockFactory.CreateMock <PhoneOrderRepository>();

            mockPhoneOrderRepository.Expects.One.Method(x => x.InsertPhoneOrder(null)).WithAnyArguments();
            phoneOrderService.SetPrivateField("phoneOrderRepository", mockPhoneOrderRepository.MockObject);
            Mock <PhoneOrderEntityFactory> mockPhoneOrderEntityFactory = mockFactory.CreateMock <PhoneOrderEntityFactory>();

            mockPhoneOrderEntityFactory.Expects.One.Method(y => y.GetInstance()).WillReturn(phoneOrderEntityFromFactory);
            phoneOrderService.SetPrivateField("phoneOrderEntityFactory", mockPhoneOrderEntityFactory.MockObject);

            sw.Write(".");
            sw.Flush();
            ms.Position = 0;
            response    = phoneOrderService.CreatePhoneOrder(ms);

            sw.Close();
            ms.Close();

            Assert.AreEqual("{\"result\":\"Done\",\"count\":0,\"orders\":null}", response);
        }
         static void Main(string[] args)
         {
             //initialize the PhoneOrderService
             var phoneOrderService = new PhoneOrderService();
             
             //initialize the phone model
             var phone1 = new Phone
             {
                 Model = "IPhone 5",
                 Price = 450,
                 QuantityInStock = 5,
                 Brand = "Brand new",
                 PhoneType = PhoneType.Apple
             };
 
             //initialize the phone model
             var phone2 = new Phone
             {
                 Model = "Nokia Lumia",
                 Price = 500,
                 QuantityInStock = 3,
                 Brand = "Brand new",
                 PhoneType = PhoneType.Windows
             };
 
             //initialize the phone model
             var phone3 = new Phone
             {
                 Model = "Galaxy 4 tab",
                 Price = 350,
                 QuantityInStock = 7,
                 Brand = "Brand new",
                 PhoneType = PhoneType.Samsung
             };
 
             //Add the phones to the phone order service
             phoneOrderService.AddToStock(phone1);
             phoneOrderService.AddToStock(phone2);
             phoneOrderService.AddToStock(phone3);
 
 
             //Initialize the customer model
             var customer = new Customer
             {
                 Name = "Mr Moon",
                 AvaliableBalance = 1000,
                 Address = "41 new street road!",
                 AccountNumber = 1234567889
             };
 
             customer.Buy(phone1);
 
             Console.ReadLine();
         }
         public void Buy(Phone phone)
         {
             if (phone == null)
                 return;
             var phoneService = new PhoneOrderService();
 
             if (phoneService.PurchasePhone(this, phone.Model))
             {
                 Console.WriteLine("{0} phone purchased!", phone.Model);
             }
         }
Esempio n. 4
0
        public void ResetRecords()
        {
            PhoneOrderService           phoneOrderService        = new PhoneOrderService();
            Mock <PhoneOrderRepository> mockPhoneOrderRepository = mockFactory.CreateMock <PhoneOrderRepository>();

            mockPhoneOrderRepository.Expects.One.Method(x => x.Reset());
            phoneOrderService.SetPrivateField("phoneOrderRepository", mockPhoneOrderRepository.MockObject);

            String response = phoneOrderService.ResetRecords();

            Assert.AreEqual("{\"result\":\"Done\",\"count\":0,\"orders\":null}", response);
        }
Esempio n. 5
0
        public void CreateDefaultOrder()
        {
            PhoneOrderService           phoneOrderService        = new PhoneOrderService();
            Mock <PhoneOrderRepository> mockPhoneOrderRepository = mockFactory.CreateMock <PhoneOrderRepository>();

            mockPhoneOrderRepository.Expects.One.Method(x => x.InsertPhoneOrder(null)).WithAnyArguments();
            phoneOrderService.SetPrivateField("phoneOrderRepository", mockPhoneOrderRepository.MockObject);

            String response = phoneOrderService.CreateDefaultOrder();

            Assert.AreEqual("{\"result\":\"Done\",\"count\":0,\"orders\":null}", response);
        }
Esempio n. 6
0
        public void GetAllRecords()
        {
            PhoneOrderService           phoneOrderService        = new PhoneOrderService();
            List <PhoneOrderEntity>     orders                   = new List <PhoneOrderEntity>();
            PhoneOrderEntityFactory     phoneOrderEntityFactory  = new PhoneOrderEntityFactory();
            Mock <PhoneOrderRepository> mockPhoneOrderRepository = mockFactory.CreateMock <PhoneOrderRepository>();
            const String expectedResult = "{\"result\":\"Done\",\"count\":0,\"orders\":[{\"first_name\":\"John\",\"last_name\":\"Smith\"," +
                                          "\"street\":null,\"city\":null,\"zipcode\":0,\"phone_number\":null,\"status\":0,\"id\":\"00000000-0000-0000-0000-000000000000\"," +
                                          "\"placed_on\":\"0001-01-01T00:00:00\"}]}";

            phoneOrderEntityFactory.SetName("John", "Smith");
            orders.Add(phoneOrderEntityFactory.GetInstance());
            mockPhoneOrderRepository.Expects.One.Method(x => x.GetOrderList()).WillReturn(orders);
            phoneOrderService.SetPrivateField("phoneOrderRepository", mockPhoneOrderRepository.MockObject);

            String response = phoneOrderService.GetAllRecords();

            Assert.AreEqual(expectedResult, response);
        }
Esempio n. 7
0
        public void UpdateOrderStatusFailed()
        {
            PhoneOrderService phoneOrderService           = new PhoneOrderService();
            PhoneOrderEntity  phoneOrderEntityFromFactory = new PhoneOrderEntity();
            MemoryStream      ms = new MemoryStream();
            StreamWriter      sw = new StreamWriter(ms);
            String            response;

            Mock <PhoneOrderRepository> mockPhoneOrderRepository = mockFactory.CreateMock <PhoneOrderRepository>();

            mockPhoneOrderRepository.Expects.One.Method(x => x.UpdateStatus(null)).WithAnyArguments().WillReturn(false);
            phoneOrderService.SetPrivateField("phoneOrderRepository", mockPhoneOrderRepository.MockObject);

            sw.Write("{\"status\":1, \"id\":\"00000000-0000-0000-0000-000000000000\"}");
            sw.Flush();
            ms.Position = 0;

            response = phoneOrderService.UpdateOrderStatus(ms);

            sw.Close();
            ms.Close();

            Assert.AreEqual("{\"result\":\"Incomplete\",\"count\":0,\"orders\":null}", response);
        }