public void Handles_invalidreason() { var actualInvalidreasons = Enum.GetValues(typeof(invalidreason)).Cast <invalidreason>().ToArray(); var expectedInvalidreasons = new[] { invalidreason.INVALID_ORGANISATION_NUMBER, invalidreason.INVALID_PERSONAL_IDENTIFICATION_NUMBER, invalidreason.UNKNOWN }; Assert.NotStrictEqual(expectedInvalidreasons, actualInvalidreasons); foreach (var reason in actualInvalidreasons) { //Arrange var nonEssentialFirstParameter = IdentificationResultType.InvalidReason; //Act var identificationResult = new IdentificationResult(nonEssentialFirstParameter, reason.ToString()); //Assert Assert.NotNull(identificationResult.Error.ToString()); Assert.Null(identificationResult.Data); } }
private static PlantOutput?ProcessResult(IdentificationResult identificationResult) { var possibleSpecies = identificationResult.Results; if (!possibleSpecies.Any()) { return(null); } var topResult = possibleSpecies .OrderByDescending(_ => _.Score) .First(); if (topResult?.Species == null) { return(null); } var identifiedSpecies = topResult.Species; return(new Output.PlantOutput( identifiedSpecies.ScientificNameWithoutAuthor, identifiedSpecies.CommonNames, topResult.Gbif?.Id)); }
public void Handles_identificationresultcode() { var actualidentificationresultcodes = Enum.GetValues(typeof(identificationresultcode)).Cast <identificationresultcode>().ToArray(); var expectedidentificationresultcodes = new[] { identificationresultcode.DIGIPOST, identificationresultcode.IDENTIFIED, identificationresultcode.INVALID, identificationresultcode.UNIDENTIFIED }; Assert.NotStrictEqual(expectedidentificationresultcodes, actualidentificationresultcodes); foreach (var resultcode in actualidentificationresultcodes) { var isFailedIdentificationresultcodes = resultcode == identificationresultcode.INVALID || resultcode == identificationresultcode.UNIDENTIFIED; //Arrange var nonEssentialFirstParameter = IdentificationResultType.InvalidReason; if (isFailedIdentificationresultcodes) { //Act var identificationResult = new IdentificationResult(nonEssentialFirstParameter, resultcode.ToString()); //Assert Assert.NotNull(identificationResult.Error.ToString()); Assert.Null(identificationResult.Data); } } }
public void IdentifyByNameAndAddress() { // Arrange var identification = new IdentifyModel { FullName = "Testulf testesen", AddressLine1 = "Vegen bortafor vegen", PostalCode = "0401", City = "Mordor" }; var identificationResult = new IdentificationResult(IdentificationResultType.DigipostAddress, DigipostAddress); var controller = IdentifyControllerWithMockedDigipostServiceAndSessionState(identificationResult); // Act var result = controller.IdentifyByNameAndAddress(identification).Result as PartialViewResult; // Assert Assert.IsNotNull(result); var viewName = result.ViewName; Assert.AreEqual("IdentificationResult", viewName); Assert.IsInstanceOfType(result.Model, typeof (IdentificationResult)); var viewModel = result.Model as IdentificationResult; Assert.AreEqual(DigipostAddress, viewModel.Data); }
private static IdentificationResult IdentificationResultForDigipostOrPersonalIdentificationNumber(identificationresult identificationResultDto) { IdentificationResult identificationResult; switch (identificationResultDto.result) { case identificationresultcode.DIGIPOST: identificationResult = new IdentificationResult(IdentificationResultType.DigipostAddress); break; case identificationresultcode.IDENTIFIED: identificationResult = new IdentificationResult(IdentificationResultType.Personalias); break; default: throw new ArgumentOutOfRangeException(); } return(identificationResult); }
public void IdentificationByPinReturnsDigipostResultWithNoneResultType() { //Arrange var source = new identificationresult { result = identificationresultcode.DIGIPOST, Items = new object[] { null } //ItemsElementName = new [] { }, //IdentificationResultCode = IdentificationResultCode.Digipost, //IdentificationValue = null, //IdentificationResultType = IdentificationResultType.None }; var expected = new IdentificationResult(IdentificationResultType.DigipostAddress, string.Empty); //Act var actual = DataTransferObjectConverter.FromDataTransferObject(source); //Assert Comparator.AssertEqual(expected, actual); }
public void Identify() { // Arrange var identification = new IdentifyModel { IdentificationType = IdentificationType.DigipostAddress, IdentificationValue = DigipostAddress }; var identificationResult = new IdentificationResult(IdentificationResultType.DigipostAddress, DigipostAddress); var controller = IdentifyControllerWithMockedDigipostServiceAndSessionState(identificationResult); // Act var result = controller.IdentifyById(identification).Result as PartialViewResult; // Assert Assert.IsNotNull(result); var viewName = result.ViewName; Assert.AreEqual("IdentificationResult", viewName); Assert.IsInstanceOfType(result.Model, typeof (IdentificationResult)); var viewModel = result.Model as IdentificationResult; Assert.AreEqual(DigipostAddress, viewModel.Data); }
public void IdentificationByAddressReturnsIdentifiedResultWithPersonalAliasResultType() { //Arrange const string personAlias = "fewoinf23nio3255n32oi5n32oi5n#1234"; var source = new identificationresult { result = identificationresultcode.IDENTIFIED, Items = new object[] { personAlias }, ItemsElementName = new[] { ItemsChoiceType.personalias } //IdentificationResultCode = IdentificationResultCode.Identified, //IdentificationValue = personAlias, //IdentificationResultType = IdentificationResultType.Personalias }; var expected = new IdentificationResult(IdentificationResultType.Personalias, personAlias); //Act var actual = DataTransferObjectConverter.FromDataTransferObject(source); //Assert Comparator.AssertEqual(expected, actual); }
public void IdentificationByAddressReturnsDigipostResultWithDigipostAddressResultType() { //Arrange const string digipostAddress = "ola.nordmann#1234"; var source = new identificationresult { result = identificationresultcode.DIGIPOST, Items = new object[] { digipostAddress }, ItemsElementName = new[] { ItemsChoiceType.digipostaddress } //IdentificationResultCode = IdentificationResultCode.Digipost, //IdentificationValue = digipostAddress, //IdentificationResultType = IdentificationResultType.DigipostAddress }; var expected = new IdentificationResult(IdentificationResultType.DigipostAddress, digipostAddress); //Act var actual = DataTransferObjectConverter.FromDataTransferObject(source); //Assert Comparator.AssertEqual(expected, actual); }
public void IdentificationByPinReturnsInvalidResultWithInvalidReason() { //Arrange object invalidValue = invalidreason.INVALID_PERSONAL_IDENTIFICATION_NUMBER; var source = new identificationresult { result = identificationresultcode.INVALID, Items = new[] { invalidValue }, ItemsElementName = new[] { ItemsChoiceType.invalidreason } //IdentificationResultCode = IdentificationResultCode.Invalid, //IdentificationValue = invalidValue, //IdentificationResultType = IdentificationResultType.InvalidReason }; var expected = new IdentificationResult(IdentificationResultType.InvalidReason, invalidValue.ToString()); //Act var actual = DataTransferObjectConverter.FromDataTransferObject(source); //Assert Comparator.AssertEqual(expected, actual); }
public void IdentificationByOrganizationNumberReturnsUnidentifiedResultWithUnidentifiedReason() { //Arrange var reason = unidentifiedreason.NOT_FOUND; var source = new identificationresult { result = identificationresultcode.UNIDENTIFIED, Items = new object[] { reason }, ItemsElementName = new[] { ItemsChoiceType.unidentifiedreason } //IdentificationResultCode = IdentificationResultCode.Unidentified, //IdentificationValue = reason, //IdentificationResultType = IdentificationResultType.UnidentifiedReason }; var expected = new IdentificationResult(IdentificationResultType.UnidentifiedReason, reason.ToString()); //Act var actual = DataTransferObjectConverter.FromDataTransferObject(source); //Assert Comparator.AssertEqual(expected, actual); }
public void Successful_IdentificationResultType_sets_data_not_error() { //Arrange var actualEnumValues = Enum.GetValues(typeof(ItemsChoiceType)).Cast <ItemsChoiceType>().ToArray(); var expectedEnumValues = new[] { ItemsChoiceType.digipostaddress, ItemsChoiceType.invalidreason, ItemsChoiceType.personalias, ItemsChoiceType.unidentifiedreason }; Assert.NotStrictEqual(expectedEnumValues, actualEnumValues); foreach (var enumValue in actualEnumValues) { var isSuccessfulItemsChoiceType = enumValue == ItemsChoiceType.digipostaddress || enumValue == ItemsChoiceType.personalias; //Act var resultCode = isSuccessfulItemsChoiceType ? "Digipost-address, personalias or empty" : "UNIDENTIFIED"; var identificationResult = new IdentificationResult(enumValue.ToIdentificationResultType(), resultCode); if (isSuccessfulItemsChoiceType) { //Assert Assert.Equal(resultCode, identificationResult.Data); Assert.Null(identificationResult.Error); } else { //Assert Assert.NotNull(identificationResult.Error); Assert.Null(identificationResult.Data); } } }
public void Handles_unidentifiedreason() { var actualUnidentifiedreasons = Enum.GetValues(typeof(unidentifiedreason)).Cast <unidentifiedreason>().ToArray(); var expectedUnidentifiedreasons = new[] { unidentifiedreason.MULTIPLE_MATCHES, unidentifiedreason.NOT_FOUND }; Assert.NotStrictEqual(expectedUnidentifiedreasons, actualUnidentifiedreasons); foreach (var reason in actualUnidentifiedreasons) { //Arrange var nonEssentialFirstParameter = IdentificationResultType.InvalidReason; //Act var identificationResult = new IdentificationResult(nonEssentialFirstParameter, reason.ToString()); //Assert Assert.NotNull(identificationResult.Error.ToString()); Assert.Null(identificationResult.Data); } }
private static IdentifyController IdentifyControllerWithMockedDigipostServiceAndSessionState( IdentificationResult identificationResult) { var digipostService = new Mock<DigipostService>(); digipostService.Setup(x => x.Identify(It.IsAny<Identification>())).ReturnsAsync(identificationResult); var controller = new IdentifyController(digipostService.Object); var context = new Mock<HttpContextBase>(); var session = new Mock<HttpSessionStateBase>(); context.Setup(x => x.Session).Returns(session.Object); var requestContext = new RequestContext(context.Object, new RouteData()); controller.ControllerContext = new ControllerContext(requestContext, controller); return controller; }