Exemplo 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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);
        }