Beispiel #1
0
        public async Task CustomerIntegrationTest()
        {
            // Create DB Context
            var configuration = new ConfigurationBuilder()
                                .AddJsonFile("appsettings.json")
                                .AddEnvironmentVariables()
                                .Build();

            var optionsBuilder = new DbContextOptionsBuilder <CustomerContext>();

            optionsBuilder.UseSqlServer(configuration["ConnectionStrings:DefaultConnection"]);

            var context = new CustomerContext(optionsBuilder.Options);

            // Just to make sure: Delete all existing customers in the DB
            await context.Database.EnsureDeletedAsync();

            await context.Database.EnsureCreatedAsync();

            // Create Controller
            var controller = new CustomersController(context);

            // Add customer
            await controller.Add(new Customer()
            {
                CustomerName = "FooBar"
            });

            // Check: Does GetAll return the added customer?
            var result = (await controller.GetAll()).ToArray();

            Assert.Single(result);
            Assert.Equal("FooBar", result[0].CustomerName);
        }
Beispiel #2
0
        public void CreateTest()
        {
            CustomersVM vm = _controller.Wtm.CreateVM <CustomersVM>();
            Customers   v  = new Customers();

            v.CusName      = "FnN6ZV7";
            v.CusGrade     = SCMSupplyChain.Model.CusGrade.VIP1;
            v.CusCompany   = "32bio";
            v.CusMan       = "B7358aReV";
            v.CusTelephone = "uohl9Ebf";
            v.CusDesc      = "FIpOlvhn";
            vm.Entity      = v;
            var rv = _controller.Add(vm);

            Assert.IsInstanceOfType(rv, typeof(OkObjectResult));

            using (var context = new DataContext(_seed, DBTypeEnum.Memory))
            {
                var data = context.Set <Customers>().Find(v.ID);

                Assert.AreEqual(data.CusName, "FnN6ZV7");
                Assert.AreEqual(data.CusGrade, SCMSupplyChain.Model.CusGrade.VIP1);
                Assert.AreEqual(data.CusCompany, "32bio");
                Assert.AreEqual(data.CusMan, "B7358aReV");
                Assert.AreEqual(data.CusTelephone, "uohl9Ebf");
                Assert.AreEqual(data.CusDesc, "FIpOlvhn");
                Assert.AreEqual(data.CreateBy, "user");
                Assert.IsTrue(DateTime.Now.Subtract(data.CreateTime.Value).Seconds < 10);
            }
        }
Beispiel #3
0
        public void AddCustomersSuccessPosttoMockDb()
        {
            var cust_id = Guid.NewGuid();
            var cust    = new Customer
            {
                customer_id     = cust_id,
                name            = "Test1",
                billing_address = " 123 Cherry Oak Street",
                billing_city    = "Hilliard",
                billing_state   = "OH",
                billing_zip     = "43221",
                isActive        = true
            };

            var vm = new CustomerViewModel(cust);

            var mockCust = new Mock <DbSet <Customer> >();

            mockCust.Setup(m => m.Find(cust_id)).Returns(cust);

            var mockContext = new Mock <StoreDbContext>();

            mockContext.Setup(m => m.Customers).Returns(mockCust.Object);

            var controller = new CustomersController(mockContext.Object);
            var result     = controller.Add(vm);

            mockContext.Verify(m => m.SaveChanges());
            mockCust.Verify(m => m.Add(It.IsAny <Customer>()), Times.Once());
            Assert.IsAssignableFrom(typeof(RedirectToRouteResult), result);
        }
Beispiel #4
0
        public void Add_WhenCalled_ReturnsObjWithId()
        {
            //Arrange
            var input = new Api.Models.Customer()
            {
                Name = "Test", Email = "*****@*****.**"
            };

            // Act
            var result   = _controller.Add(input);
            var okResult = (OkObjectResult)result;

            // Assert
            Assert.IsType <OkObjectResult>(result);
            Assert.IsType <Api.Models.Customer>(okResult.Value);
            Assert.True(((Api.Models.Customer)okResult.Value).Id > 0);
        }
Beispiel #5
0
        public void AddCustomersSuccessViewRenders()
        {
            var db         = new StoreDbContext();
            var controller = new CustomersController(db);
            var result     = controller.Add();

            Assert.IsAssignableFrom(typeof(ViewResult), result);
        }
        public async void ShouldCreateCustomer()
        {
            var customer    = CreateCustomer();
            var customerDto = MapCustomerToDto(customer);

            _customerRepositoryMock.Setup(o => o.Add(customer)).Returns(Task.FromResult(true));
            _customerServiceMock.Setup(o => o.Add(customer)).Returns(Task.FromResult(true));
            _mapperMock.Setup(m => m.Map <Customer>(It.IsAny <CustomerDto>())).Returns(customer);

            var result = await _customersController.Add(customerDto);

            Assert.IsType <ActionResult <CustomerDto> >(result);
            Assert.IsType <OkObjectResult>(result.Result);
        }
Beispiel #7
0
        public void Create(int Id, string Name, string Location)
        {
            //Arrange
            var cust = new Customer
            {
                Id       = Id,
                Name     = Name,
                Location = Location
            };

            _serviceMock.Setup(x => x.Add(It.IsAny <Customer>()));

            //Act
            _customersController.Add(cust);

            //Assert
            _serviceMock.Verify(x => x.Add(It.IsAny <Customer>()), Times.Once, "anymessage");
        }
Beispiel #8
0
        public void AddShouldReturnUnprocessableEntityIfModelStateIsInvalid()
        {
            // Arrange
            var mock = new Mock <ICustomerService>();

            Service    = mock.Object;
            Controller = new CustomersController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();
            Controller.ModelState.AddModelError("", "");
            var mockCustomer = Builder <CustomerAddModel> .CreateNew().Build();

            // Act
            var result = Controller.Add(mockCustomer);

            // Assert
            Assert.AreEqual(422, (int)result.StatusCode);
        }
Beispiel #9
0
        public void AddShouldReturnInternalServerErrorIfServiceAddReturnsFalse()
        {
            // Arrange
            var mock = new Mock <ICustomerService>();

            mock.Setup <bool>(_ => _.Add(It.IsAny <CustomerAddModel>()))
            .Returns(false);
            Service    = mock.Object;
            Controller = new CustomersController(Service);
            Controller.Configuration = new HttpConfiguration();
            Controller.Request       = new HttpRequestMessage();
            var mockCustomer = Builder <CustomerAddModel> .CreateNew().Build();

            // Act
            var result = Controller.Add(mockCustomer);

            // Assert
            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
        }
Beispiel #10
0
        // Fyller databasen med data om den är tom.
        public static void FillData()
        {
            CustomersController    cController = new CustomersController();
            BicyclesController     bController = new BicyclesController();
            InvoiceInfoController  iController = new InvoiceInfoController();
            RentalOrdersController oController = new RentalOrdersController();
            RentalPricesController pController = new RentalPricesController();

            string[] firstNames  = { "Tobias", "Oliver", "Bilbo", "Ninmar", "Robin", "Erik", "Johan", "Anders", "Johanna", "Sofia" };
            string[] lastNames   = { "Nyholm", "Stenström", "Baggins", "Karlsson", "Kamo", "Niklasson", "Johansson", "Svensson", "Enberg", "Svensson" };
            int[]    phoneNumers = { 0768645167, 0763669581, 0758981235, 0752125886, 0735669852, 0752778412, 0769721001, 0705723698, 0768645112, 0758996521 };

            for (int i = 0; i < 10; i++)
            {
                cController.Add(new Customers {
                    first_name = firstNames[i], last_name = lastNames[i], phone_number = phoneNumers[i]
                });
            }

            double[] hourPrices = { 150, 160, 170, 180, 190, 200, 210, 220, 230, 240 };
            double[] dayPrices  = { 2000, 2200, 2300, 2400, 2500, 2600, 2700, 2800, 2900, 3000 };

            for (int i = 0; i < 10; i++)
            {
                pController.Add(new Rental_Prices {
                    hour_price = hourPrices[i], day_price = dayPrices[i]
                });
            }

            string[] status          = { "Rented", "Rented", "Rented", "Rented", "Rented", "Rented", "Rented", "Rented", "Rented", "Rented" };
            string[] models          = { "Trek", "Colnago", "Raleigh", "BMC", "Cervelo", "Colnago", "Trek", "BMX", "BMC", "Cersent" };
            int[]    priceCategories = { 1, 2, 3, 4, 5, 6, 7, 3, 5, 1 };

            for (int i = 0; i < 10; i++)
            {
                bController.Add(new Bicycles {
                    model = models[i], price_category = priceCategories[i], rental_status = status[i]
                });
            }

            string[] returnDates = { "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00", "2021-04-26 07:00:00" };
            int[]    customerID  = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int[]    bicycleID   = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            for (int i = 0; i < 10; i++)
            {
                oController.Add(new Rental_Orders {
                    return_date = returnDates[i], customer_id = customerID[i], bicycle_id = bicycleID[i]
                });
            }

            string[] invoiceAdresses = { "Lärdomsgatan 9", "Envägen 5", "Hobbit road 5", "Wallaby way 42", "Sjuntorpsgatan 7", "Hagen 82", "Dammhagen 228", "Inlandsvägen 2", "Klammergatan 8", "Vägen 1" };
            string[] coAdresses      = { "LGH 1011", "Baksidan", "You shall not pass", "P. Sherman", "", "", "Lugnet", "", "Klammen", "Gatan" };
            int[]    postalNumbers   = { 41753, 46375, 44231, 47116, 41671, 44852, 48231, 47593, 44752, 42351 };
            string[] cities          = { "Göteborg", "Enköping", "Fylke", "Sydney", "Sjuntorp", "Haga town", "Hjärtum", "Västerås", "Klammerville", "Uppfarten" };
            int[]    orderNumbers    = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

            for (int i = 0; i < 10; i++)
            {
                iController.Add(new Invoice_Info {
                    invoice_adress = invoiceAdresses[i], co_adress = coAdresses[i], postal_number = postalNumbers[i], city = cities[i], customer_id = customerID[i], order_number = orderNumbers[i], first_name = firstNames[i], last_name = lastNames[i]
                });
            }
        }