public void Get_WhenCalled_ReturnsOkResult() { // Arrange var customersToReturn = new List <CustomerViewModel>(); customersToReturn.Add( new CustomerViewModel { FirstName = "Cliente A", LastName = "Last name A", Address = "Avenue A", PersonalNumber = "0508851234" }); customersToReturn.Add( new CustomerViewModel { FirstName = "Cliente B", LastName = "Last name B", Address = "Avenue B", PersonalNumber = "0101874321" }); _mockCustomerAppService.Setup(c => c.GetAll()).Returns(customersToReturn); // Act var okResult = _customerController.Get(); // Assert Assert.IsType <OkObjectResult>(okResult); }
public void Get_Returns_All() { // Act var results = _controller.Get() as ActionResult <IEnumerable <Customer> >; // Assert var items = Assert.IsType <ActionResult <IEnumerable <Customer> > >(results); }
public async Task Get_Returns_Expected() { var result = await controller.Get(1); Assert.IsTrue(!(result.Result is NotFoundResult), "There is no data in db"); Assert.IsTrue(result.Value.Id == 1, "Returned data is not correct"); }
public void GetInvocesReviewGetById() { GetReady(); //var actRes = ; var response = controller.Get(1).ExecuteAsync(CancellationToken.None).Result; Assert.IsNotNull(response.Content); }
public void GetAllCustomers() { TestHelper.InitDatabase(); GetReady(); var actRes = controller.Get(); var response = actRes.ExecuteAsync(CancellationToken.None).Result; Assert.IsNotNull(response.Content); }
public void GetAll_ReturnsListWithCorrectNumberOfCustomers() { // Act var result = controller.Get() as List <Customer>; var noOfCustomers = result.Count; // Assert Assert.Equal(3, noOfCustomers); }
public async Task GetCustomerValidTest() { var result = await _customersController.Get(CustomerMotherObject.ValidCustomer().PublicId); var contentResult = (OkObjectResult)result; var customer = (CustomerOutput)contentResult.Value; Assert.IsType <OkObjectResult>(contentResult); Assert.Equal(200, contentResult.StatusCode); Assert.IsType <CustomerOutput>(contentResult.Value); Assert.Equal(CustomerMotherObject.ValidCustomer().Name, customer.Name); }
public void Get_UnknownIdPassed_ReturnsNull() { // Assert var id = -1; // Act var result = _controller.Get(id); // Assert var resultOk = Assert.IsType <OkObjectResult>(result); Assert.Null(resultOk.Value); }
public async Task CustomersController_Get() { //Arrange GetCustomer gc = new GetCustomer(); gc.Id = Guid.NewGuid(); //Act var result = await controller.Get(gc); var contentResult = result as ActionResult <CustomerDto>; //Assert contentResult.Should().NotBeNull(); }
public void SetUp() { _customers = new[] { new Customer { FirstName = "Max", LastName = "Verstappen", Email = "*****@*****.**", Password = "******" }, new Customer { FirstName = "Daniel", LastName = "Ricciardo", Email = "*****@*****.**", Password = "******" }, new Customer { FirstName = "Kimi", LastName = "Raikkonen", Email = "*****@*****.**", Password = "******" } }; var customersRepository = new Mock <ICustomersRepository>(); customersRepository.Setup(mock => mock.Get()).Returns(_customers); var subject = new CustomersController(customersRepository.Object); _result = subject.Get() as OkObjectResult; }
public async Task Get_Returns_Expected_Customer() { // Arrange var customer = CustomerFixture.Customers().FirstOrDefault(x => x.Id == 1); mockCustomerService.Setup(service => service.Get(1)).Returns(Task.FromResult <Customer>(customer)); // Act var result = await controller.Get(1); // Assert var objectResult = Assert.IsType <OkObjectResult>(result); var actual = Assert.IsAssignableFrom <Customer>(objectResult.Value); Assert.Equal(customer.Id, actual.Id); }
public void Get() { CustomersController controller = new CustomersController(); var result = controller.Get(); Assert.IsNotNull(result); }
public async void CustomerController_GetCustomers_MatchResult() { //Arrange var controller = new CustomersController(customersDAL); //Act var data = await controller.Get(); //Assert var okObjectResult = data as OkObjectResult; Assert.NotNull(okObjectResult); var modelList = okObjectResult.Value as List <Customer>; Assert.NotNull(modelList); Assert.IsType <OkObjectResult>(data); Assert.Equal(SeedData.DummyCompanyNames[0], modelList[0].CompanyName); Assert.Equal(SeedData.DummyContactNames[0], modelList[0].ContactName); Assert.Equal(SeedData.DummyAddresses[0], modelList[0].Address); Assert.Equal(SeedData.DummyCities[0], modelList[0].City); Assert.Equal(SeedData.DummyRegions[0], modelList[0].Region); Assert.Equal(SeedData.DummyPostalCodes[0], modelList[0].PostalCode); Assert.Equal(SeedData.DummyCountries[0], modelList[0].Country); Assert.Equal(SeedData.DummyPhones[0], modelList[0].Phone); }
public void CustomersControllerTests_ConstructorShouldReturnList_No_Error() { var customers = new List <CustomerModel>() { new CustomerModel() { Id = 1, Name = "William" } }; var mediator = new Mock <IMediator>(); var tcs = new TaskCompletionSource <List <CustomerModel> >(); tcs.SetResult(customers); mediator.Setup(m => m.Send(It.IsAny <GetCustomersListQuery1>(), It.IsAny <CancellationToken>())).Returns(tcs.Task); // Act var controller = new CustomersController(mediator.Object); var results = controller.Get() as System.Web.Http.Results.OkNegotiatedContentResult <System.Collections.Generic.List <CustomerModel> >; // Assert Assert.AreEqual(results.Content.FirstOrDefault(), customers.FirstOrDefault()); //var results = controller.Get() as System.Web.Http.Results.OkNegotiatedContentResult<System.Collections.Generic.IEnumerable<EmployeeModel>>; //Assert.AreEqual(results.Content.ToList().Single(), employee); }
public void Get_WhenCalledWithNoParam_ShouldListAllCustomers() { // Arrange var testDataContext = new DataFileData { Customers = _testCustomers }; var customersRepository = new CustomersRepository(new DatabaseFactory(testDataContext)); var customersServicesInst = new CustomersServices(customersRepository); //var mockStaticLoggerInstWrapper = new Mock<IStaticLoggerInstanceWrapper>(); var customersController = new CustomersController(customersServicesInst); // Act var response = customersController.Get(); // Assert Assert.IsNotNull(response); Assert.IsInstanceOfType(response, typeof(OkObjectResult)); var items = (List <Customer>)((OkObjectResult)response).Value; Assert.AreEqual(3, items.Count); }
public async void CustomerController_GetCustomerById_MatchResult() { //Arrange var controller = new CustomersController(customersDAL); //Act // Our test database is seeded with seedRowsCount datarows. Choose a random valid value. var rng = new Random(); var customerIndex = rng.Next(1, seedRowsCount); var data = await controller.Get(customerIndex); //Assert Assert.IsType <OkObjectResult>(data); var okResult = data.Should().BeOfType <OkObjectResult>().Subject; var customer = okResult.Value.Should().BeAssignableTo <Customer>().Subject; Assert.Equal(SeedData.DummyCompanyNames[customerIndex - 1], customer.CompanyName); Assert.Equal(SeedData.DummyContactNames[customerIndex - 1], customer.ContactName); Assert.Equal(SeedData.DummyAddresses[customerIndex - 1], customer.Address); Assert.Equal(SeedData.DummyCities[customerIndex - 1], customer.City); Assert.Equal(SeedData.DummyRegions[customerIndex - 1], customer.Region); Assert.Equal(SeedData.DummyPostalCodes[customerIndex - 1], customer.PostalCode); Assert.Equal(SeedData.DummyCountries[customerIndex - 1], customer.Country); Assert.Equal(SeedData.DummyPhones[customerIndex - 1], customer.Phone); }
public void UpdateCustomerWithWrongId(int id) { var controller = new CustomersController(context); var response = controller.Get(id) as ObjectResult; if (response == null) { Assert.Null(response); } else { Customer c = new Customer { Id = id, Name = "Updated!", Status = unit.CustomerStatuses.Get(1), Address = new CustomerAddress { City = "City" } }; response = controller.Put(id, c) as ObjectResult; var value = response.Value as EmployeeModel; Assert.AreEqual(200, response.StatusCode); Assert.AreEqual("Updated!", value.FirstName); } }
public void GetCustomerByWrongId(int id) { var controller = new CustomersController(context); var response = controller.Get(id) as ObjectResult; Assert.Null(response); }
public void GetReturnsCustomerWithSameId() { // Arrange var customer = Builder <Customer> .CreateNew() //[NBuilder] .With(x => x.CustomerID = "testId") .Build(); var customers = new List <Customer> { customer }; var mockRepository = new Mock <IRepository <Customer> >(); //[Moq] mockRepository.Setup(x => x.GetAll()) .Returns(customers.AsQueryable()); var target = new CustomersController(mockRepository.Object); // Act IHttpActionResult actionResult = target.Get("testId"); var contentResult = actionResult as OkNegotiatedContentResult <Customer>; // Assert contentResult.Should().NotBeNull(); contentResult.Content.CustomerID.Should().Be("testId"); }
public void Get_CheckCountOfGet_ReturnCount() { var controller = new CustomersController(_context); var count = _context.Customers.CountAsync().Result; var result = controller.Get(sort: "asc").CountAsync(); Assert.Equal(count, result.Result); }
public async Task GetAllCustomers() { ActionResult <IEnumerable <Customer> > response = await _controller.Get(); var customers = response.Value; Assert.IsNotNull(customers); }
public void Get(int Id) { _serviceMock.Setup(x => x.Get(Id)); _customersController.Get(Id); _serviceMock.Verify(x => x.Get(Id), Times.Once, "anymessage"); }
public async Task GetCustomerByWrongId() { var controller = new CustomersController(unit.Context); int id = 40; //Customer with id doesn't exist in the test database var response = await controller.Get(id) as ObjectResult; Assert.AreEqual(404, response.StatusCode); }
public void GetCustomerById(int id) { var controller = new CustomersController(context); var response = controller.Get(id) as ObjectResult; var value = response.Value as CustomerModel; Assert.AreEqual(200, response.StatusCode); Assert.AreEqual(1, value.Id); }
public void GetAllCustomers() { var controller = new CustomersController(context); var response = controller.Get() as ObjectResult; var value = response.Value as List <CustomerModel>; Assert.AreEqual(200, response.StatusCode); Assert.AreEqual(2, value.Count); }
public void ControllerGetAllCustomerSuccess() { var controller = new CustomersController(); var response = controller.Get(); var result = (OkNegotiatedContentResult <List <CustomerModel> >)response; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); }
public void Get_ReturnsNiceErrorMessage_WithInternalExceptionOccures() { // Arrange _mockUOW.Setup(uow => uow.GetCustomersLookup()).Throws <Exception>(); _controller = new CustomersController(_mockUOW.Object, _mockLogger, _mockConfigOptions); // Act _controller.Get(); }
public async Task Should_Return_404_When_Customer_Not_Found() { var customerServiceMock = new Mock <ICustomersService>(); var controller = new CustomersController(customerServiceMock.Object, _mapper); var result = await controller.Get(1, default); Assert.Equal(404, ((NotFoundResult)result).StatusCode); }
public void GetCustomerThatDoesntExists() { CustomersController _customersController = new CustomersController(); int expectedCustomers = 0; IEnumerable <CustomerResponse> customers = _customersController.Get(1); Assert.AreEqual(expectedCustomers, customers.Count()); }
public async Task GetCustomerByIdAsync_ShouldReturn200_WhenCustomerExist() { // arrange var customerId = 1; _customerRepository.GetCustomerByID(customerId).Returns(_customersList.FirstOrDefault(x => x.CustomerId == customerId)); // act var customerResult = (await _customerController.Get(customerId)) as ObjectResult; // assert var customer = Assert.IsAssignableFrom <Customer>( Assert.IsType <Customer>(customerResult.Value)); Assert.NotNull(customerResult); Assert.True(customerResult is OkObjectResult); Assert.Equal(customerId, customer.CustomerId); Assert.Equal(StatusCodes.Status200OK, customerResult.StatusCode); }
public void Get() { // Arrange CustomersController controller = new CustomersController(); // Act IEnumerable<Customer> result = controller.Get(); Assert.IsNotNull(result); Assert.IsTrue(result.Any()); }