public async Task VerifyCreatingReviewCallsApiWhenDataIsFilled() { var book = new DetailedBookDto(); var authService = new Mock <IAuthenticationService>(); AccountModel loggedOnUser = new AccountModel(new AuthTokenDto { Person = new PersonDto() }); authService.SetupGet(s => s.LoggedOnAccount).Returns(() => loggedOnUser); var feedbackService = new Mock <IFeedbackService>(); var viewModel = new CreateReviewViewModel(book, authService.Object, feedbackService.Object); await Should.ThrowAsync <InvalidOperationException>(async() => await viewModel.CreateReview()); feedbackService.Verify(s => s.CreateFeedback(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()), Times.Never); viewModel.Rating = 3; await Should.ThrowAsync <InvalidOperationException>(async() => await viewModel.CreateReview()); feedbackService.Verify(s => s.CreateFeedback(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()), Times.Never); viewModel.Message = "Message"; var dto = await viewModel.CreateReview(); feedbackService.Verify(s => s.CreateFeedback(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>()), Times.Once); }
public async Task VerifyValidCreateCallsApi() { var book = new DetailedBookDto { Id = 5 }; var authService = new Mock <IAuthenticationService>(); AccountModel loggedOnUser = new AccountModel(new AuthTokenDto { Person = new PersonDto() }); authService.SetupGet(s => s.LoggedOnAccount).Returns(() => loggedOnUser); var feedbackService = new Mock <IFeedbackService>(); var viewModel = new CreateReviewViewModel(book, authService.Object, feedbackService.Object) { Message = "test", Rating = 2 }; var feedback = new BookFeedbackDto(); feedbackService.Setup(s => s.CreateFeedback(5, 2, "test")).ReturnsAsync(feedback); var dto = await viewModel.CreateReview(); dto.ShouldBe(feedback); feedbackService.Verify(s => s.CreateFeedback(5, 2, "test"), Times.Once); }
public void VerifyOwnsBookChangesWhenBookIsAddedToMyBooksCollection() { var book = new DetailedBookDto { Id = 5 }; var booksService = new Mock <IBooksService>(); var collection = new ObservableServiceCollection <BookDto, BookFilter, IBooksService>(booksService.Object); booksService.SetupGet(s => s.MyBooks).Returns(collection); var shoppingCartService = new Mock <IShoppingCartService>(); var authService = new Mock <IAuthenticationService>(); var viewModel = new BookSummaryViewModel(book, booksService.Object, shoppingCartService.Object, authService.Object); int ownsBookChanged = 0; viewModel.OwnsBook.ShouldBeFalse(); viewModel.PropertyChanged += (sender, args) => { if (args.PropertyName != nameof(viewModel.OwnsBook)) { return; } ownsBookChanged++; }; collection.Add(book); viewModel.OwnsBook.ShouldBeTrue(); ownsBookChanged.ShouldBe(1); }
public async Task Get_SingleBookById() { // Arrange var bookRepo = new Mock <IBookRepository>(); var bookHistoryRepo = new Mock <IBookHistoryRepository>(); //var bookFeedbackRepo = new Mock<IBookFeedbackRepository>(); var authRepo = new Mock <IAuthenticationRepository>(); var personRepository = new Mock <IPersonRepository>(); var bookOrderRepository = new Mock <IBookOrderRepository>(); bookRepo.Setup(x => x.GetById(It.IsAny <int>())) .Returns(async(int id) => { return(GetStaticBooks().Where(x => x.Id == id).Single().ToDetailedDto()); }); var controller = new BooksController(bookRepo.Object, bookHistoryRepo.Object, authRepo.Object, personRepository.Object, bookOrderRepository.Object); // Act IHttpActionResult actionResult = await controller.Get(1); var contentResult = actionResult as OkNegotiatedContentResult <DetailedBookDto>; // Assert DetailedBookDto expectedBookDto = GetStaticBooks().First().ToDetailedDto(); Assert.IsNotNull(contentResult); Assert.IsNotNull(contentResult.Content); Assert.AreEqual(expectedBookDto.Id, contentResult.Content.Id); Assert.AreEqual(JsonConvert.SerializeObject(expectedBookDto), JsonConvert.SerializeObject(contentResult.Content)); }
public void VerifyViewModelCannotBeCreatedWhenNotLoggedIn() { var book = new DetailedBookDto(); var authenticationService = new Mock <IAuthenticationService>(); var feedbackService = new Mock <IFeedbackService>(); Should.Throw <ArgumentNullException>( () => new CreateReviewViewModel(book, authenticationService.Object, feedbackService.Object)); }
/// <summary> /// Initializes a new instance of the <see cref="ReviewsViewModel" /> class. /// </summary> /// <param name="book">The book.</param> /// <param name="feedbackService">The feedback service.</param> /// <param name="authService">The authentication service.</param> public ReviewsViewModel(DetailedBookDto book, IFeedbackService feedbackService, IAuthenticationService authService) { this.authService = authService; var feedbackFilter = new FeedbackFilter { BookId = book.Id }; this.Reviews = new ObservableServiceCollection <BookFeedbackDto, FeedbackFilter, IFeedbackService>(feedbackService, feedbackFilter); }
/// <summary> /// Initializes a new instance of the <see cref="CreateReviewViewModel"/> class. /// </summary> /// <param name="book">The book.</param> /// <param name="authService">The authentication service.</param> /// <param name="service">The service.</param> /// <exception cref="ArgumentNullException">Missing logged on user!</exception> public CreateReviewViewModel(DetailedBookDto book, IAuthenticationService authService, IFeedbackService service) { this.book = book; this.authService = authService; this.service = service; if (this.authService.LoggedOnAccount == null) { throw new ArgumentNullException(nameof(this.authService.LoggedOnAccount), "Missing logged on user!"); } }
/// <summary> /// Initializes a new instance of the <see cref="BookSummaryViewModel"/> class. /// </summary> /// <param name="book">The book.</param> /// <param name="booksService">The books service.</param> /// <param name="shoppingCartService">The shopping cart service.</param> /// <param name="authService">The authentication service.</param> /// <exception cref="ArgumentNullException"></exception> public BookSummaryViewModel(DetailedBookDto book, IBooksService booksService, IShoppingCartService shoppingCartService, IAuthenticationService authService) { if (book == null) { throw new ArgumentNullException(nameof(book)); } this.Book = book; this.booksService = booksService; this.shoppingCartService = shoppingCartService; this.authService = authService; this.booksService.MyBooks.CollectionChanged += this.MyBooks_CollectionChanged; }
public void VerifyViewModelCanBeCreatedWhenLoggedIn() { var book = new DetailedBookDto(); var authenticationService = new Mock <IAuthenticationService>(); var authToken = new AuthTokenDto { Person = new PersonDto() }; AccountModel loggedOnUser = new AccountModel(authToken); authenticationService.SetupGet(s => s.LoggedOnAccount).Returns(() => loggedOnUser); var feedbackService = new Mock <IFeedbackService>(); var viewModel = new CreateReviewViewModel(book, authenticationService.Object, feedbackService.Object); viewModel.ShouldNotBeNull(); }
/// <summary> /// Initializes a new instance of the <see cref="ReadBookViewModel" /> class. /// </summary> /// <param name="epub">The epub.</param> /// <param name="book">The book.</param> public ReadBookViewModel(byte[] epub, DetailedBookDto book) { this.Book = book; this.epub = epub; }