public void ExecuteSaveEntry_RaisesError_IfThumbnailCouldNotBeSet() { BookReference bookReference = new BookReference(); EntryReference entryRef = new EntryReference(); Entry entry = new Entry(); _viewModel.Header = "header"; _viewModel.Body = "body"; MemoryStream attachmentBinary = new MemoryStream(Encoding.UTF8.GetBytes("Barembo rockz")); Attachment attachment = new Attachment(); attachment.FileName = "attachment1.jpg"; attachment.Type = AttachmentType.Image; attachment.Size = attachmentBinary.Length; _viewModel.Attachments.Add(new MediaDataViewModel(new MediaData() { Attachment = attachment, Stream = attachmentBinary, FilePath = "pathToFile" }, _thumbnailGeneratorService.Object)); _eventAggregator.Setup(s => s.GetEvent <ErrorMessage>()).Returns(new ErrorMessage()).Verifiable(); _eventAggregator.Setup(s => s.GetEvent <InAppInfoMessage>()).Returns(new InAppInfoMessage()).Verifiable(); _entryServiceMock.Setup(s => s.CreateEntry(_viewModel.Header, _viewModel.Body)).Returns(entry).Verifiable(); _entryServiceMock.Setup(s => s.AddEntryToBookAsync(bookReference, entry)).Returns(Task.FromResult(entryRef)).Verifiable(); _entryServiceMock.Setup(s => s.AddAttachmentAsync(entryRef, entry, attachment, attachmentBinary, "pathToFile")).Returns(Task.FromResult(true)).Verifiable(); _entryServiceMock.Setup(s => s.SetThumbnailAsync(entryRef, entry, attachment, attachmentBinary, "pathToFile")).Returns(Task.FromResult(false)).Verifiable(); _viewModel.Init(bookReference); _viewModel.SaveEntryCommand.Execute(); _eventAggregator.Verify(); _entryServiceMock.Verify(); }
public async Task CreateAsync_Loads_TheBook() { BookReference bookReference = new BookReference(); Book book = new Book(); _bookServiceMock.Setup(s => s.LoadBookAsync(bookReference)).Returns(Task.FromResult(book)).Verifiable(); await BookViewModel.CreateAsync(_bookServiceMock.Object, _eventAggregator.Object, bookReference); _bookServiceMock.Verify(); _eventAggregator.Verify(); }
public void ExecuteSaveEntry_Publishes_Message() { BookReference bookReference = new BookReference(); Entry entry = new Entry(); _entryServiceMock.Setup(s => s.CreateEntry(_viewModel.Header, _viewModel.Body)).Returns(entry).Verifiable(); _eventAggregator.Setup(s => s.GetEvent <InAppInfoMessage>()).Returns(new InAppInfoMessage()).Verifiable(); _eventAggregator.Setup(s => s.GetEvent <BookEntrySavedMessage>()).Returns(new BookEntrySavedMessage()).Verifiable(); _viewModel.Init(bookReference); _viewModel.SaveEntryCommand.Execute(); _eventAggregator.Verify(); }
public async Task InitAsync_DoesSetLoadingFailed_IfLoadingFailed() { BookReference bookReference = new BookReference(); Book book = new Book(); _bookServiceMock.Setup(s => s.LoadBookAsync(bookReference)).Throws(new BookNotExistsException()).Verifiable(); await _viewModel.InitAsync(bookReference); Assert.IsTrue(_viewModel.LoadingFailed); _bookServiceMock.Verify(); _eventAggregator.Verify(); }
public async Task InitAsync_DoesNotSetLoadingFailed_IfSuccessfull() { BookReference bookReference = new BookReference(); Book book = new Book(); _bookServiceMock.Setup(s => s.LoadBookAsync(bookReference)).Returns(Task.FromResult(book)).Verifiable(); await _viewModel.InitAsync(bookReference); Assert.IsFalse(_viewModel.LoadingFailed); _bookServiceMock.Verify(); _eventAggregator.Verify(); }
public async Task InitAsync(BookReference bookReference) { IsLoading = true; try { _bookReference = bookReference; Book = await _bookService.LoadBookAsync(_bookReference); } catch (Exception ex) { LoadingFailed = true; LoadingError = ex.Message; } IsLoading = false; }
public void ExecuteSaveEntry_RaisesError_IfEntryCouldNotBeCreated() { BookReference bookReference = new BookReference(); Entry entry = null; _viewModel.Header = "header"; _viewModel.Body = "body"; _entryServiceMock.Setup(s => s.CreateEntry(_viewModel.Header, _viewModel.Body)).Returns(entry).Verifiable(); _eventAggregator.Setup(s => s.GetEvent <ErrorMessage>()).Returns(new ErrorMessage()).Verifiable(); _viewModel.Init(bookReference); _viewModel.SaveEntryCommand.Execute(); _eventAggregator.Verify(); _entryServiceMock.Verify(); }
public void ExecuteSaveEntry_Saves_AttachmentsWithSecondOneNotSettingThumbnail() { BookReference bookReference = new BookReference(); EntryReference entryRef = new EntryReference(); Entry entry = new Entry(); _viewModel.Header = "header"; _viewModel.Body = "body"; MemoryStream attachmentBinary1 = new MemoryStream(Encoding.UTF8.GetBytes("Barembo rockz")); MemoryStream attachmentBinary2 = new MemoryStream(Encoding.UTF8.GetBytes("Barembo really rockz")); Attachment attachment1 = new Attachment(); attachment1.FileName = "attachment1.jpg"; attachment1.Type = AttachmentType.Image; attachment1.Size = attachmentBinary1.Length; _viewModel.Attachments.Add(new MediaDataViewModel(new MediaData() { Attachment = attachment1, Stream = attachmentBinary1, FilePath = "pathToFile1" }, _thumbnailGeneratorService.Object)); Attachment attachment2 = new Attachment(); attachment2.FileName = "attachment2.jpg"; attachment2.Type = AttachmentType.Image; attachment2.Size = attachmentBinary2.Length; _viewModel.Attachments.Add(new MediaDataViewModel(new MediaData() { Attachment = attachment2, Stream = attachmentBinary2, FilePath = "pathToFile2" }, _thumbnailGeneratorService.Object)); _eventAggregator.Setup(s => s.GetEvent <BookEntrySavedMessage>()).Returns(new BookEntrySavedMessage()).Verifiable(); _eventAggregator.Setup(s => s.GetEvent <InAppInfoMessage>()).Returns(new InAppInfoMessage()).Verifiable(); _entryServiceMock.Setup(s => s.CreateEntry(_viewModel.Header, _viewModel.Body)).Returns(entry).Verifiable(); _entryServiceMock.Setup(s => s.AddAttachmentAsync(entryRef, entry, attachment1, attachmentBinary1, "pathToFile1")).Returns(Task.FromResult(true)).Verifiable(); _entryServiceMock.Setup(s => s.SetThumbnailAsync(entryRef, entry, attachment1, attachmentBinary1, "pathToFile1")).Returns(Task.FromResult(true)).Verifiable(); _entryServiceMock.Setup(s => s.AddAttachmentAsync(entryRef, entry, attachment2, attachmentBinary2, "pathToFile2")).Returns(Task.FromResult(true)).Verifiable(); _entryServiceMock.Setup(s => s.AddEntryToBookAsync(bookReference, entry)).Returns(Task.FromResult(entryRef)).Verifiable(); _viewModel.Init(bookReference); _viewModel.SaveEntryCommand.Execute(); _eventAggregator.Verify(); _entryServiceMock.Verify(); }
public void ExecuteSaveBookShare_SavesAndPublishesMessage() { BookReference bookReference = new BookReference(); StoreAccess storeAccess = new StoreAccess(); BookShareReference bookShareReference = new BookShareReference(); _viewModel.ContributorName = "Tim"; _viewModel.BookName = "MyBook"; _viewModel.AccessRights.CanAddEntries = true; _bookShelfServiceMock.Setup(s => s.ShareBookAsync(storeAccess, bookReference, _viewModel.ContributorName, _viewModel.AccessRights, _viewModel.BookName)).Returns(Task.FromResult(bookShareReference)).Verifiable(); _eventAggregator.Setup(s => s.GetEvent <BookShareSavedMessage>()).Returns(new BookShareSavedMessage()).Verifiable(); _viewModel.Init(storeAccess, bookReference); _viewModel.SaveBookShareCommand.Execute(); _eventAggregator.Verify(); }
public void ExecuteSaveBookShare_RaisesError_IfBookShareCouldNotBeCreated() { BookReference bookReference = new BookReference(); StoreAccess storeAccess = new StoreAccess(); BookShareReference bookShareReference = new BookShareReference(); _viewModel.ContributorName = "Tim"; _viewModel.BookName = "MyBook"; _viewModel.AccessRights.CanAddEntries = true; _eventAggregator.Setup(s => s.GetEvent <ErrorMessage>()).Returns(new ErrorMessage()).Verifiable(); _bookShelfServiceMock.Setup(s => s.ShareBookAsync(storeAccess, bookReference, _viewModel.ContributorName, _viewModel.AccessRights, _viewModel.BookName)).Throws(new BookShareCouldNotBeSavedException()).Verifiable(); _viewModel.Init(storeAccess, bookReference); _viewModel.SaveBookShareCommand.Execute(); _eventAggregator.Verify(); _bookShelfServiceMock.Verify(); }
public void ExecuteSaveEntry_InformsUser_AboutSavedEntry() { BookReference bookReference = new BookReference(); EntryReference entryRef = new EntryReference(); Entry entry = new Entry(); _viewModel.Header = "header"; _viewModel.Body = "body"; _eventAggregator.Setup(s => s.GetEvent <BookEntrySavedMessage>()).Returns(new BookEntrySavedMessage()).Verifiable(); _eventAggregator.Setup(s => s.GetEvent <InAppInfoMessage>()).Returns(new InAppInfoMessage()).Verifiable(); _entryServiceMock.Setup(s => s.CreateEntry(_viewModel.Header, _viewModel.Body)).Returns(entry).Verifiable(); _entryServiceMock.Setup(s => s.AddEntryToBookAsync(bookReference, entry)).Returns(Task.FromResult(entryRef)).Verifiable(); _viewModel.Init(bookReference); _viewModel.SaveEntryCommand.Execute(); _eventAggregator.Verify(); _entryServiceMock.Verify(); }
public static async Task <BookViewModel> CreateAsync(IBookService bookService, IEventAggregator eventAggregator, BookReference bookReference) { var bookVM = new BookViewModel(bookService, eventAggregator); await bookVM.InitAsync(bookReference).ConfigureAwait(false); return(bookVM); }
public void Init(StoreAccess storeAccess, BookReference bookReference) { _storeAccess = storeAccess; _bookReference = bookReference; }
public void Init(BookReference bookReference) { _bookReference = bookReference; }