Ejemplo n.º 1
0
        public async Task Create_Returns_SuccessResponse()
        {
            // Arrange

            mockCustomerService.Setup(service => service.Create(It.IsAny <Customer>())).Returns(Task.FromResult <int>(1));

            // Act
            var result = await controller.Create(new Customer());

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }
Ejemplo n.º 2
0
        public void Create_should_return_edit_view()
        {
            // Arrange
            var viewNames = new[] { null, "Edit" };

            // Act
            var result   = _controller.Create() as ViewResult;
            var viewName = result.ViewName;

            // Assert
            Assert.Contains(viewName, viewNames);
        }
Ejemplo n.º 3
0
        public void Create_InvaliCustomerPassed_ReturnsBadRequest()
        {
            var dateOfBirthMissingCustomer = new Customer()
            {
                FirstName = "Beth",
                LastName  = "Miller"
            };

            _controller.ModelState.AddModelError("DateOfBirth", "Required");

            var badResponse = _controller.Create(dateOfBirthMissingCustomer);

            Assert.IsType <BadRequestObjectResult>(badResponse.Result);
        }
Ejemplo n.º 4
0
        public void Create_ValidObject_ReturnsCreatedAtRouteResult()
        {
            Customer testItem = new Customer()
            {
                FirstName = "First name",
                Surname   = "Surname",
                Email     = "*****@*****.**",
                Password  = "******"
            };

            var response = _controller.Create(testItem).Result as CreatedAtRouteResult;

            Assert.IsType <CreatedAtRouteResult>(response);
        }
Ejemplo n.º 5
0
        public void CreateTest()
        {
            CustomersController controller = new CustomersController();
            var result = controller.Create();

            Assert.IsNotNull(result);
        }
Ejemplo n.º 6
0
        public void TestCreatePost_NewCustomer()
        {
            #region ASSIGN

            TestRepository      tRepo       = new TestRepository();
            CustomersController tController = null;

            Customer newCustomer = new Customer()
            {
                FirstName = "Me",
                LastName  = "Guy",
                StateID   = 0
            };

            tController = new CustomersController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("User"),
            };

            #endregion

            #region ACT

            var tResult = tController.Create(newCustomer);

            #endregion

            #region ASSERT

            Assert.IsTrue(tResult is RedirectToActionResult);

            #endregion
        }
        public async void Create_ExistedID_ReturnViewResultCustomer(int id)
        {
            var customer = new Customer {
                FirstName = "RamilQ", LastName = "NaumQ" + id.ToString(), Address = "LosQ-Ang", Discount = "5", Id = id
            };
            var option = new DbContextOptionsBuilder <ShoppingContext>().
                         UseInMemoryDatabase(databaseName: "testsCreate").Options;
            var context = new ShoppingContext(option);

            SampleData.Initialize(context);
            var mock       = new Mock <CustomersService>(context);
            var controller = new CustomersController(mock.Object);
            var resultView = await controller.Create(customer);

            var viewResult = Assert.IsType <RedirectToActionResult>(resultView);
            var actionName = Assert.IsAssignableFrom <string>(viewResult.ActionName);

            var resultViewDetails = await controller.Details(id);

            var viewResultDetails = Assert.IsType <ViewResult>(resultViewDetails);
            var model             = Assert.IsAssignableFrom <Customer>(viewResultDetails.Model);

            Assert.Equal("Index", actionName);
            Assert.Equal(model, customer);
        }
Ejemplo n.º 8
0
        public void TestCreateGet_ExistingCustomer()
        {
            #region ASSIGN

            TestRepository      tRepo       = new TestRepository();
            CustomersController tController = null;

            tController = new CustomersController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("UserA"),
            };

            #endregion

            #region ACT

            var tResult = tController.Create();

            #endregion

            #region ASSERT

            Assert.IsTrue(tResult is RedirectToActionResult);
            Assert.AreEqual((tResult as RedirectToActionResult).ActionName, "Index");

            #endregion
        }
Ejemplo n.º 9
0
        public void TestCreateViewBag_Invalid()
        {
            #region ASSIGN

            TestRepository      tRepo       = new TestRepository();
            CustomersController tController = null;

            tController = new CustomersController(tRepo)
            {
                ControllerContext = UtilityFunctions.GenerateMockControllerContext("User"),
            };

            #endregion

            #region ACT

            var tResult = tController.Create() as ViewResult;

            #endregion

            #region ASSERT

            var tList = tResult.ViewData["StateID"] as SelectList;

            var tItem = tList.Where(a => a.Value == "1").FirstOrDefault().Text;

            Assert.AreNotEqual(tItem, "FL");

            #endregion
        }
        public void GetCreateShouldReturnCustomerView()
        {
            var customersController = new CustomersController();
            var result = customersController.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Customer));
        }
Ejemplo n.º 11
0
        public void Create_WithAnyCreate_ReturnTrue()
        {
            // Act
            controller.Create(It.IsAny <Customer>());

            // Assert Id Room
            fakeCustomerRepository.Verify(x => x.Add(It.IsAny <Customer>()), Times.Once);
        }
Ejemplo n.º 12
0
        public void GetCreateShouldReturnCustomerView()
        {
            var customersController = new CustomersController();
            var result = customersController.Create() as ViewResult;

            Assert.AreEqual("Create", result.ViewName);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Customer));
        }
Ejemplo n.º 13
0
        public void CreateCustomer()
        {
            var service    = new Mock <ICustomerRepository>();
            var controller = new CustomersController(service.Object);

            var result = controller.Create();

            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
        public void Create()
        {
            ApplicationDbContext context    = new ApplicationDbContext();
            IUnitOfWork          unitOfWork = new UnitOfWork(context);
            var controller = new CustomersController(unitOfWork);
            var result     = controller.Create() as ViewResult;

            Assert.AreEqual(expected: "Create", actual: result.ViewName);
        }
        public void Create_ReturnsViewResultWithCustomer(int id, string email, string name)
        {
            // Act
            var customer = new Customer()
            {
                Id = id, Email = email, Name = name
            };

            controller.Create(customer);
            // Assert against the mock object
            fakeCustomerRepository.Verify(x => x.Add(It.Is <Customer>(z => z == customer)), Times.Once);
        }
        public async void CreateUser_ActionExecutes_ReturnResultWithCustomerDto()
        {
            CreateCustomerDto newCustomer = new CreateCustomerDto()
            {
                Email = "mail3", UserName = "******", Password = "******"
            };

            _mockService.Setup(x => x.CreateUserAsync(newCustomer)).ReturnsAsync(Response <CustomerDto> .Success(customers.Find(x => x.Id == "ses"), 200));
            var result = await _controller.Create(newCustomer);

            Assert.IsType <ObjectResult>(result);
        }
Ejemplo n.º 17
0
        public void CreateCustomer()
        {
            //  arrange
            var controller = new CustomersController();

            //  act
            var customer = new Customer();
            var result   = controller.Create(customer) as OkObjectResult;


            Assert.NotNull(result);
        }
Ejemplo n.º 18
0
        public async Task Create_CustomerReturnsViewResultWithCustomerModel()
        {
            controller = new CustomersController(mock.Object);
            controller.ModelState.AddModelError("Name", "Required");
            Customer newCustomer = new Customer();

            var result = await controller.Create(newCustomer);

            var viewResult = Assert.IsType <ViewResult>(result);

            Assert.Equal(newCustomer, viewResult?.Model);
        }
Ejemplo n.º 19
0
        public void CreateOrder()
        {
            var options = new DbContextOptionsBuilder <OrderContext>()
                          .UseInMemoryDatabase(databaseName: "create_order")
                          .Options;

            Customer customer;
            Item     item;
            Order    order;

            using (var context = new OrderContext(options))
            {
                var controller = new CustomersController(context);
                customer = controller.Create(new CreateCustomer {
                    Name = "customer"
                });
                customer.Name.ShouldEqual("customer");
            }


            using (var context = new OrderContext(options))
            {
                var controller = new ItemsController(context);
                item = controller.Create(new CreateItem {
                    Name = "item"
                });
                item.Name.ShouldEqual("item");
            }

            using (var context = new OrderContext(options))
            {
                var controller = new OrdersController(context);
                order = controller.Create(new CreateOrder {
                    CustomerId = customer.Id
                });
                order.Customer.Name.ShouldEqual(customer.Name);
            }

            using (var context = new OrderContext(options))
            {
                var controller = new OrdersController(context);
                order = controller.GetById(order.Id);
                order.Customer.Name.ShouldEqual(customer.Name);
            }

            // using (var context = new OrderContext(options))
            // {
            //     var controller = new OrdersController(context);
            //     order = controller.Update(new CreateOrder { CustomerId = customer.Id });
            //     order.Customer.Name.ShouldEqual(customer.Name);
            // }
        }
        public void CreateShouldCreateNewCustomer()
        {
            // Given
            A.CallTo(() => _createCustomerCommand.Run(Constants.CoolCustomer)).Returns(Constants.CoolCustomer);

            // When
            var customer = _customersController.Create(Constants.CoolCustomer);

            // Then
            Assert.Equal(Constants.CoolCustomer, customer);

            A.CallTo(() => _createCustomerCommand.Run(Constants.CoolCustomer)).MustHaveHappened();
        }
Ejemplo n.º 21
0
        public async Task CreateValidCustomer()
        {
            var validCustomer = new Customer()
            {
                FirstName = "Tomasz", LastName = "Nowak", Email = "*****@*****.**"
            };

            var service    = new Mock <ICustomerRepository>();
            var controller = new CustomersController(service.Object);

            var result = await controller.Create(validCustomer);

            Assert.IsInstanceOfType(result, typeof(RedirectToActionResult));
        }
        public void When_CreateCalled_NewCustomerCreated()
        {
            var dbMock   = new Mock <ICustomerRepository>();
            var customer = new Customer {
                Id = 104, Firstname = "Neo", Lastname = "Trinity"
            };

            // Subject under test.
            var sut = new CustomersController(dbMock.Object);

            sut.Create(customer);

            dbMock.Verify(_ => _.Create(It.Is <Customer>(c => c == customer)));
            //dbMock.VerifyAll();
        }
Ejemplo n.º 23
0
        public async Task Post_shouldReturnBadRequestWhenPersonNameIsEmpty()
        {
            Customer customer = new Customer()
            {
                Cpf   = "83684303054",
                Name  = String.Empty,
                State = "PR"
            };

            Moq.Mock <ICustomerService> mockCustomerService = new Moq.Mock <ICustomerService>();
            mockCustomerService.Setup(customerService => customerService.CreateAsync(It.IsAny <Customer>())).Returns(Task.FromResult(customer));
            var customerController = new CustomersController(mockCustomerService.Object);

            var response = await customerController.Create(customer.Name, customer.State, customer.Cpf);

            Assert.IsType <BadRequestObjectResult>(response.Result);
        }
Ejemplo n.º 24
0
        public async Task Post_shouldReturnBadRequestWhenPersonIdIsInvalid()
        {
            Customer customer = new Customer()
            {
                Cpf   = "7868",
                Name  = "Ramires",
                State = "RJ"
            };

            Moq.Mock <ICustomerService> mockCustomerService = new Moq.Mock <ICustomerService>();
            mockCustomerService.Setup(customerService => customerService.CreateAsync(It.IsAny <Customer>())).Returns(Task.FromResult(customer));
            var customerController = new CustomersController(mockCustomerService.Object);

            var response = await customerController.Create(customer.Name, customer.State, customer.Cpf);

            Assert.IsType <BadRequestObjectResult>(response.Result);
        }
Ejemplo n.º 25
0
        public void CreatingANewCustomer_AddsItToTheDb()
        {
            var controller = new CustomersController(this.session);

            var viewModel = new CreateOrEditCustomerViewModel {
                Name = "Pippo", VATNumber = "12345678901"
            };

            var result = controller.Create(viewModel);

            var redirectResult = result as RedirectToRouteResult;
            var action         = redirectResult.RouteValues["action"];

            var reportOnDb = this.session.Get <Customer>(1);

            reportOnDb.Should().Not.Be.Null();
        }
Ejemplo n.º 26
0
        public void EditCustome_Success()
        {
            CustomersController controller = new CustomersController();
            var singup = new Customer
            {
                ID           = 1,
                CustomerCode = "bbb",
                CustomerName = "phat1111",
                PhoneNumber  = "09876",
                Address      = "dia chi cua phat",
                //YearOfBirth = DateTime.Parse("Jan ,01, 2009")
            };

            var result = controller.Create(singup) as RedirectToRouteResult;

            Assert.AreEqual("Index", result.RouteValues["Action"]);
        }
        public void SetUp()
        {
            _customer = new Customer
            {
                FirstName = "New",
                LastName  = "Customer",
                Email     = "*****@*****.**",
                Password  = "******"
            };

            _customerRepository = new Mock <ICustomersRepository>();
            _customerRepository.Setup(mock => mock.Create(It.IsAny <Customer>())).Callback(() => _customer.Id = 1);

            var subject = new CustomersController(_customerRepository.Object);

            _result         = subject.Create(_customer) as CreatedAtActionResult;
            _resultCustomer = _result.Value as Customer;
        }
Ejemplo n.º 28
0
        public async Task CreateInvalidCustomer()
        {
            string invalidLastName = "Wrong customer name";
            var    invalidCustomer = new Customer()
            {
                FirstName = "Tomasz", LastName = invalidLastName, Email = "*****@*****.**"
            };

            var service    = new Mock <ICustomerRepository>();
            var controller = new CustomersController(service.Object);

            controller.ModelState.AddModelError("", "");

            var result = await controller.Create(invalidCustomer);

            var model = (Customer)((ViewResult)result).Model;

            Assert.AreEqual(invalidLastName, model.LastName);
        }
Ejemplo n.º 29
0
        public void CreatingACustomerTwoTimes_IsNotAllowed()
        {
            this.session.Save(new Customer {
                Name = "Pippo", VATNumber = "12345678901"
            });
            var controller = new CustomersController(this.session);
            var viewModel  = new CreateOrEditCustomerViewModel {
                Name = "Pippo", VATNumber = "12345678901"
            };

            var result = controller.Create(viewModel);

            var viewResult = result as ViewResult;

            viewResult.Should().Not.Be.Null();
            var error = viewResult.ViewData.ModelState["VATNumber"].Errors[0];

            Assert.AreEqual("Un cliente con stessa partita Iva è già presente.", error.ErrorMessage);
        }
Ejemplo n.º 30
0
        public async Task Create_Customer()
        {
            // Arrange
            var mockRepo = new Mock <IRepository>();
            var custTest = new StoreApp.DataAccess.BusinessModels.Customer(1);

            custTest.FirstName = "Jordan";
            custTest.LastName  = "garcia";
            custTest.Phone     = "9992221111";
            var viewmodel  = new CustomerViewModel(custTest);
            var controller = new CustomersController(mockRepo.Object);

            // Act
            var result = await controller.Create(viewmodel);

            // Assert

            Assert.True(controller.ModelState.IsValid);
        }
Ejemplo n.º 31
0
        public async Task Create_CustomerReturns_RedirectToActionResult()
        {
            controller = new CustomersController(mock.Object);
            Customer newCustomer = new Customer
            {
                FirstName = "Ramil",
                LastName  = "Naum",
                Address   = "Los-Ang",
                Discount  = "5"
            };


            var result = await controller.Create(newCustomer);

            var redirectToActionResult = Assert.IsType <RedirectToActionResult>(result);

            Assert.Null(redirectToActionResult.ControllerName);
            Assert.Equal("Index", redirectToActionResult.ActionName);
            mock.Verify(r => r.AddAsync(newCustomer));
        }
        public void PostCreateShouldSaveCustomerAndReturnDetailsView()
        {
            var customersController = new CustomersController();
            var customer = new Customer
            {
                Name = "Hugo Reyes",
                Email = "*****@*****.**",
                Phone = "720-123-5477"
            };

            var result = customersController.Create(customer) as ViewResult;

            Assert.IsNotNull(result);
            Assert.AreEqual("Details", result.ViewName);
            Assert.IsInstanceOfType(result.ViewData.Model, typeof(Customer));

            customer = result.ViewData.Model as Customer;
            Assert.IsNotNull(customer);
            Assert.IsTrue(customer.Id > 0);
        }