public async Task <ItemDataModel> CreateFromAsync(IDataFactory dataFactorySource, IDataFactory dataFactoryDestination, ItemDataModel itemDataModelSource, ItemDataModel itemDataModelDestinationParent, bool isTransfert, object data = null) { var itemDataModelDestination = await AddSiteCommand.DuplicateItemAsync(dataFactoryDestination, itemDataModelSource, itemDataModelDestinationParent, isTransfert, data); if (string.IsNullOrEmpty(itemDataModelDestination.Id)) { // Pour les image on a besoin de forcer l'id itemDataModelDestination.Id = Guid.NewGuid().ToString(); } // TODO a supprimer hiostorique image { var items = await dataFactorySource.ItemRepository.GetItemsAsync(itemDataModelSource.SiteId, new ItemFilters { ParentId = itemDataModelSource.Id }); if (items != null) { var allLists = items.OrderBy(i => i.Index); foreach (var item in allLists) { await AddSiteCommand.DuplicateItemAsync(dataFactoryDestination, item, itemDataModelDestination, isTransfert, data); } } } // Nouvelles images stream { var files = await dataFactorySource.ItemRepository.DownloadsAsync(itemDataModelSource.SiteId, itemDataModelSource.Id, true); if (files != null) { var allLists = files.OrderBy(i => i.Index); foreach (var file in allLists) { await DuplicateFileAsync(dataFactoryDestination, file, itemDataModelDestination, isTransfert, data); } } } return(itemDataModelDestination); }
public void ExceptionThrownIfUrlNotGiven() { // Arrange. var ctx = new Context(); var sut = new AddSiteCommand(ctx); // Act and Assert. Assert.Throws<ArgumentException>(() => sut.Execute()); }
public void ExceptionThrownIfUrlNotGiven() { // Arrange. var ctx = new Context(); var sut = new AddSiteCommand(ctx); // Act and Assert. Assert.Throws <ArgumentException>(() => sut.Execute()); }
public async Task <CommandResult <dynamic> > Add([FromServices] AddSiteCommand _addSiteCommand, [FromBody] AddSiteInput addSiteInput) { var userId = User != null && User.Identity != null?User.GetUserId() : string.Empty; var userInput = new UserInput <AddSiteInput> { Data = addSiteInput, UserId = userId }; var result = await Business.InvokeAsync <AddSiteCommand, UserInput <AddSiteInput>, CommandResult <dynamic> >( _addSiteCommand, userInput); return(result); }
public void AddingNewSiteResultsInOneSiteReturned() { // Arrange. var ctx = new Context(); var sut = new AddSiteCommand(ctx) { Url = "AnyUrl" }; // Act. sut.Execute(); var query = new ListSitesQuery(ctx); var result = query.Execute(); // Assert. Assert.Equal(1, result.Sites.Count); }
public ResultDto NewSite(SiteDto siteDto) { return(Result(() => { var command = new AddSiteCommand { SiteTitle = siteDto.Title, Name = siteDto.Name, IsActive = siteDto.IsActive, IsPublic = siteDto.IsPublic, IsDefault = siteDto.IsDefault, Description = siteDto.Description, OwnerUsername = User.Identity.Name, // current user }; CommandDispatcher.Send(command); })); }
public void AddingNewSiteResultsInOneSiteReturned() { // Arrange. var ctx = new Context(); var sut = new AddSiteCommand(ctx) { Url = "AnyUrl" }; // Act. sut.Execute(); var query = new ListSitesQuery(ctx); var result = query.Execute(); // Assert. Assert.Equal(1, result.Sites.Count); }