Exemplo n.º 1
0
        public void GetByIdWhenExistingIdPassedReturnsOkResult()
        {
            int testId   = 1;
            var okResult = controller.GetCustomerById(testId);

            Assert.IsType <OkObjectResult>(okResult.Result);
        }
Exemplo n.º 2
0
        public void GetById_Should_Return_As_200OKResult()
        {
            //Arrange
            _mediator.Setup(s => s.Send(It.IsAny <GetCustomerByIdQuery>(), default)).Returns(Task.FromResult(_customerDataResponse.Object));
            _customerDataResponse.Setup(t => t.Success).Returns(true);
            _customerDataResponse.Setup(t => t.StatusCode).Returns(StatusCodes.Status200OK);
            _customerDataResponse.Setup(s => s.Data).Returns(_customerResponse);

            //Act
            var actual = _sut.GetCustomerById(_customerId).GetAwaiter().GetResult();

            //Assert
            actual.GetType().Should().Equals(StatusCodes.Status200OK);
        }
Exemplo n.º 3
0
        public void GetCustomerById()
        {
            var fakeCustomer = new Customer();

            _customerRepository.GetCustomer(Arg.Any <int>()).Returns(fakeCustomer);
            _customerRepository.Exists(Arg.Any <int>()).Returns(true);

            IActionResult actionResult = _controller.GetCustomerById(1);
            var           result       = actionResult as OkObjectResult;
            var           customer     = result.Value as Customer;

            _customerRepository.Received(1).Exists(1);
            _customerRepository.Received(1).GetCustomer(1);
            Assert.AreSame(fakeCustomer, customer);
        }
Exemplo n.º 4
0
        public void GetCustomer_ShouldReturnCorrectCustomer()
        {
            var result = controller.GetCustomerById(1) as OkNegotiatedContentResult <Customer>;

            Assert.IsNotNull(result);
            Assert.AreEqual(data.Customers.GetById(1).Name = "Asya", result.Content.Name = "Asya");
        }
        public async Task CustomerController_GetCustomerById_Ok()
        {
            var db         = _contextBuilder.ConfigureInMemory().Add1Customer().Build();
            var repository = new Repository <Models.Customer>(db);
            var controller = new CustomersController(repository);

            var response = (await controller.GetCustomerById(1)).Result as OkObjectResult;

            var values = response.Value as Models.Customer;

            values.Id.Should().Be(1);
        }
Exemplo n.º 6
0
        public void Test_GetCustomerById()
        {
            // Arrange

            // Act
            var result        = controller.GetCustomerById(Guid.NewGuid());
            var contentResult = result as OkNegotiatedContentResult <CustomerViewModel>;
            var content       = contentResult.Content;

            // Assert
            Assert.IsNotNull(contentResult);
            Assert.AreEqual(mockCustomer.Guid, content.Guid);
            Assert.AreEqual(mockCustomer.Number, content.Number);
            Assert.AreEqual(mockCustomer.Address.City, content.Address.City);
        }
Exemplo n.º 7
0
        public void GetCustomerById_ReturnsNotFound_GivenBadId()
        {
            // Arrange
            var customersRepo = new Mock <ICustomerRepository>();

            customersRepo.Setup(x => x.GetCustomerById(It.IsAny <int>())).Returns((CustomerDto)null);
            var customersManipulation = new CustomerManipulation(customersRepo.Object);
            var controller            = new CustomersController(customersManipulation);

            // Act
            var result = controller.GetCustomerById(1);

            // Assert
            Assert.IsType <NotFoundObjectResult>(result);
        }
            public void ShouldReturnCustomerBasedOnId(int customerId, Customer expectedCustomer)
            {
                // arrange
                _customerRepo.GetCustomerById(1)
                .Returns(GetFirstMockCustomer());
                _customerRepo.GetCustomerById(2)
                .Returns(GetSecondMockCustomer());

                // act
                var actionResult   = _customersController.GetCustomerById(customerId);
                var okObjectResult = actionResult.Result as OkObjectResult;
                var actualCustomer = okObjectResult.Value as Customer;

                // assert
                Assert.IsType <OkObjectResult>(okObjectResult);
                Assert.Equal(actualCustomer.FirstName, expectedCustomer.FirstName);
                Assert.Equal(actualCustomer.LastName, expectedCustomer.LastName);
            }
Exemplo n.º 9
0
        public void GetCustomerById_ReturnsOK()
        {
            // Arrange
            int id       = 1;
            var customer = new CustomerDto()
            {
                AddressId        = 1,
                PricingPackageId = 1,
                CustomerName     = "firstname"
            };
            var customersRepo = new Mock <ICustomerRepository>();

            customersRepo.Setup(x => x.GetCustomerById(It.IsAny <int>())).Returns(customer);
            var customersManipulation = new CustomerManipulation(customersRepo.Object);
            var controller            = new CustomersController(customersManipulation);

            // Act
            var result = controller.GetCustomerById(1);

            // Assert
            Assert.IsType <OkObjectResult>(result);
        }