public void WHEN_Convert_GIVEN_Valid_Dto_THEN_Get_Valid_Result_With_All_Links() { var uniqueIdFactory = SampleObjectsIdFactory.Instance; var growerDto = new GrowerDto { Uid = Guid.NewGuid(), Name = "Test" }; var converter = new GrowerDtoConverter(uniqueIdFactory); var grower = converter.Convert(growerDto); Assert.Equal(growerDto.Uid.ToString(), grower.Object.Id.UniqueIds.First().Id); Assert.Equal(growerDto.Name, grower.Object.Name); var selfLink = grower.Links.Single(l => l.Rel == Relationships.Self); Assert.Equal($"/Growers/{uniqueIdFactory.UniqueIdSource}/{growerDto.Uid}", selfLink.Link); Assert.Equal(selfLink.Id.ReferenceId, grower.Object.Id.ReferenceId); var farmsLink = grower.Links.Single(l => l.Rel == typeof(Farm).ListRel()); Assert.Equal($"/Growers/{uniqueIdFactory.UniqueIdSource}/{growerDto.Uid}/Farms", farmsLink.Link); var fieldsLink = grower.Links.Single(l => l.Rel == typeof(Field).ListRel()); Assert.Equal($"/Growers/{uniqueIdFactory.UniqueIdSource}/{growerDto.Uid}/Fields", fieldsLink.Link); }
public ModelEnvelope <Grower> Get(string source, string id) { SampleObjectsIdFactory.ValidateSource(source); var dto = SampleRepository.Instance.Growers.Single(f => f.Uid == new Guid(id)); var converter = new GrowerDtoConverter(SampleObjectsIdFactory.Instance); return(converter.Convert(dto)); }
public IReadOnlyCollection <ModelEnvelope <Grower> > Get() { var list = new List <ModelEnvelope <Grower> >(); var converter = new GrowerDtoConverter(SampleObjectsIdFactory.Instance); foreach (var dto in SampleRepository.Instance.Growers) { var envelope = converter.Convert(dto); list.Add(envelope); } return(list); }