public void Should_convert_uuid_uri_node() { // given const string GuidStr = "6cbb1450-c74d-47e8-a1e0-50f1db6cfd6f"; var uri = new Uri(string.Format("urn:uuid:{0}", GuidStr)); var uriNode = Node.ForUri(uri); // when var guid = _converter.Convert(uriNode, new Mock <IEntityContext>().Object); // then guid.Should().Be(new Guid(GuidStr)); }
public void ConvertToGuid_Success() { var guid = Guid.NewGuid(); Assert.True(converter.CanConvert(guid.GetType())); var dict = converter.Convert(guid, settings); Assert.Equal(guid.ToString(), dict); var result = converter.ConvertBack(dict, settings); Assert.Equal(guid, result); }
public void Conversion() { // Arrange IConverter converter = new GuidConverter(); var expectedValue = Guid.NewGuid(); var value = expectedValue.ToString(); // Act var actualValue = converter.Convert(value, converter.TargetType); // Assert Assert.NotNull(actualValue); Assert.IsType <Guid>(actualValue); Assert.Equal(expectedValue, (Guid)actualValue); }
public IHttpActionResult GetCareHomesDetailsByResidentRefId(string referenceId) { if (string.IsNullOrEmpty(referenceId)) { throw new ArgumentNullException(nameof(referenceId)); } var resident = _residentService.GetResident(GuidConverter.Convert(referenceId)); if (resident == null) { return(BadRequest("Cannot find resident. Please contact admin.")); } var careHomeDetail = _careHomeService.GetCareHomesDetails(resident.CareHomeId); return(Ok(careHomeDetail)); }
public void BadValueConversion() { // Arrange IConverter converter = new GuidConverter(); var value = "Hello"; var expectedExceptionMessage = Constants.ExceptionMessages.FormatConverterUnableConvert(value, typeof(Guid)); var expectedInnerExceptionMessage = "Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)."; // Act using (new LangageSwitcher("en-us")) { var actualException = Assert.Throws <CommandLineParserException>(() => converter.Convert(value, converter.TargetType)); // Assert Assert.Equal(expectedExceptionMessage, actualException.Message); Assert.NotNull(actualException.InnerException); var actualInnerExecption = Assert.IsAssignableFrom <FormatException>(actualException.InnerException); Assert.Equal(expectedInnerExceptionMessage, actualInnerExecption.Message); } }