public async Task UploadValidIdentityNumberFiles_Test_ReturnsOk() { // Arrange var identityNumberService = new IdentityNumberService(_fixture.MockValidIdentityNumberRepository.Object, _fixture.MockInvalidIdentityNumberRepository.Object); var controller = new IdentityNumberController(_fixture.Configuration, identityNumberService); var fileMock = new Mock <IFormFile>(); var content = "8501015800088" + Environment.NewLine + "85010" + Environment.NewLine; const string fileName = "IdentityNumbers.txt"; var ms = new MemoryStream(); var writer = new StreamWriter(ms); writer.Write(content); writer.Flush(); ms.Position = 0; ms.SetLength(content.Length); fileMock.Setup(_ => _.OpenReadStream()).Returns(ms); fileMock.Setup(_ => _.FileName).Returns(fileName); fileMock.Setup(_ => _.Length).Returns(ms.Length); // Act var result = await controller.ValidateUploadFilesAsync(new List <IFormFile> { fileMock.Object }); // Assert Assert.NotNull(result); var actionResult = Assert.IsType <ActionResult <IdentityNumberListModel> >(result); var objectResult = Assert.IsType <OkObjectResult>(actionResult.Result); var model = Assert.IsType <IdentityNumberListModel>(objectResult.Value); Assert.Single(model.ValidIdentityNumbers); Assert.Single(model.InvalidIdentityNumbers); }
public async Task PostNullIdentityNumbers_Test_ReturnsBadRequest() { // Arrange var identityNumberService = new IdentityNumberService(_fixture.MockValidIdentityNumberRepository.Object, _fixture.MockInvalidIdentityNumberRepository.Object); var controller = new IdentityNumberController(_fixture.Configuration, identityNumberService); // Act var result = await controller.ValidateInputAsync(null); // Assert Assert.NotNull(result); Assert.IsType <BadRequestObjectResult>(result.Result); }
public void SetUp() { _dataRepository = new Mock <IDataRepository>(); //_dataRepository.Setup(x => x.Save(It.IsAny<List<ValidIDInfo>>(), It.IsAny<FileCsvType>())); _hostingEnvironment = new Mock <IHostingEnvironment>(); _formFile = new Mock <IFormFile>(); _logger = new Mock <ILogger <IdentityNumberController> >(); _configuration = ConfigurationSetup.SetUpConfiguration(); _identityNumberService = new TestIdentityNumberService(_configuration); _identityNumberValidator = new TestIdentityNumberValidator(_identityNumberService); _identityNumberController = new IdentityNumberController(_dataRepository.Object, _identityNumberValidator, _identityNumberService, _hostingEnvironment.Object, _logger.Object); SetUpDataRepository(); }
public async Task PostValidIdentityNumbers_Test_ReturnsOk() { // Arrange var identityNumberService = new IdentityNumberService(_fixture.MockValidIdentityNumberRepository.Object, _fixture.MockInvalidIdentityNumberRepository.Object); var controller = new IdentityNumberController(_fixture.Configuration, identityNumberService); // Act var result = await controller.ValidateInputAsync(GetIdentityNumbers()); // Assert Assert.NotNull(result); var actionResult = Assert.IsType <ActionResult <IdentityNumberListModel> >(result); var objectResult = Assert.IsType <OkObjectResult>(actionResult.Result); var model = Assert.IsType <IdentityNumberListModel>(objectResult.Value); Assert.Single(model.ValidIdentityNumbers); Assert.Single(model.InvalidIdentityNumbers); }
public async Task GetValidNumbers_Test_ReturnsOk() { // Arrange _fixture.MockValidIdentityNumberRepository.Setup(r => r.GetAsync()).ReturnsAsync(GetValidIdentityNumbers()); _fixture.MockIdentityNumberService.Setup(s => s.GetValidAsync()) .ReturnsAsync(GetValidIdentityNumbers()); var identityNumberService = new IdentityNumberService(_fixture.MockValidIdentityNumberRepository.Object, _fixture.MockInvalidIdentityNumberRepository.Object); var controller = new IdentityNumberController(_fixture.Configuration, identityNumberService); // Act var result = await controller.GetValidNumbersAsync(); // Assert Assert.NotNull(result); var actionResult = Assert.IsType <ActionResult <List <ValidIdentityNumber> > >(result); var objectResult = Assert.IsType <OkObjectResult>(actionResult.Result); var value = Assert.IsType <List <ValidIdentityNumber> >(objectResult.Value); Assert.Single(value); }