public async Task GetExportProfileReturnsProfileAndPhotoDataTest() { var profileId = Guid.NewGuid(); var profile = ModelBuilder.Model.Create <Profile>(); var photos = ModelBuilder.Model.Ignoring <Photo>(x => x.Data).Create <List <Photo> >(); var photoData = ModelBuilder.Model.Create <byte[]>(); var profileQuery = Substitute.For <IProfileQuery>(); var photoQuery = Substitute.For <IPhotoQuery>(); using (var inputStream = new MemoryStream(photoData)) { photos.SetEach(x => x.Data = inputStream); using (var tokenSource = new CancellationTokenSource()) { profileQuery.GetProfile(profileId, tokenSource.Token).Returns(profile); photoQuery.GetPhotos(profileId, tokenSource.Token).Returns(photos); var sut = new ExportQuery(profileQuery, photoQuery); var actual = await sut.GetExportProfile(profileId, tokenSource.Token).ConfigureAwait(false); actual.Should().BeEquivalentTo(profile, opt => opt.ExcludingMissingMembers()); actual.Photos.Should().BeEquivalentTo(photos, opt => opt.Excluding(x => x.Data)); actual.Photos.All(x => x.Data.SequenceEqual(photoData)).Should().BeTrue(); } } }
public void GetExportProfileThrowsExceptionWithEmptyProfileIdTest() { var profileQuery = Substitute.For <IProfileQuery>(); var photoQuery = Substitute.For <IPhotoQuery>(); var sut = new ExportQuery(profileQuery, photoQuery); Func <Task> action = async() => await sut.GetExportProfile(Guid.Empty, CancellationToken.None).ConfigureAwait(false); action.Should().Throw <ArgumentException>(); }
public Task <Result <IEnumerable <ExportQuery.WarehouseDto> > > Handle(ExportQuery request, CancellationToken token) { var result = _repository.Warehouses .OrderByDescending(w => w.Count) .ThenByDescending(w => w.Name) .Select(w => new ExportQuery.WarehouseDto() { Name = w.Name, Count = w.Count, Materials = w.Materials .OrderBy(m => m.Id) .Select(m => new ExportQuery.MaterialDto() { Id = m.Id, Count = m.Count }) }); return(Result.OkAsync(result)); }