Exemplo n.º 1
0
        public async Task HasAGetSaleQueryResultAsync()
        {
            var saleExpected = new Sale(new List <SaleAlbum> {
                new SaleAlbum("teste", "classical", 10)
            });

            var saleRepositoryMock = new Mock <ISaleRepository>();

            saleRepositoryMock.Setup(x => x.GetSale(It.IsAny <Guid>())).Returns(saleExpected);

            var genrePercentExpected = new GenresPercent(Genres.POP, DateTime.Now.DayOfWeek, 10);

            var genreRepositoryMock = new Mock <IGenreRepository>();

            genreRepositoryMock.Setup(x => x.GetPercent(It.IsAny <string>(), It.IsAny <DayOfWeek>())).Returns(genrePercentExpected);

            var queryResult = await new GetSaleQueryHandler(saleRepositoryMock.Object, genreRepositoryMock.Object).Handle(new GetSaleQuery(saleExpected.Id), new CancellationToken());

            Assert.NotNull(queryResult);
            Assert.Equal(saleExpected.Id, queryResult.Id);
            Assert.Equal(saleExpected.Albums.Count(), queryResult.Albums.Count());
        }
Exemplo n.º 2
0
        public async Task HasAPaginatedQueryResultOfGetSalePaginatedAsync()
        {
            var salesExpected = new List <Sale> {
                new Sale(new List <SaleAlbum> {
                    new SaleAlbum("teste", "classical", 10)
                })
            };

            var saleRepositoryMock = new Mock <ISaleRepository>();

            saleRepositoryMock.Setup(x => x.GetPagedSales(It.IsAny <DateTime?>(), It.IsAny <DateTime?>(), It.IsAny <int>(), It.IsAny <int>())).Returns(salesExpected);

            var genrePercentExpected = new GenresPercent(Genres.POP, DateTime.Now.DayOfWeek, 10);

            var genreRepositoryMock = new Mock <IGenreRepository>();

            genreRepositoryMock.Setup(x => x.GetPercent(It.IsAny <string>(), It.IsAny <DayOfWeek>())).Returns(genrePercentExpected);

            var queryResult = await new GetPaginatedSalesQueryHandler(saleRepositoryMock.Object, genreRepositoryMock.Object)
                              .Handle(new GetPaginatedSalesQuery(null, null, 0, 10), new CancellationToken());

            Assert.NotNull(queryResult);
            Assert.NotEmpty(queryResult.Data);
        }
Exemplo n.º 3
0
        public async Task CanAddNewSaleAsync()
        {
            var saleRepositoryMock = new Mock <ISaleRepository>
            {
                CallBase = true,
            };

            saleRepositoryMock.Setup(x => x.SaveSale(It.IsAny <Sale>())).Returns(Guid.NewGuid());

            var genrePercentExpected = new GenresPercent(Genres.POP, DateTime.Now.DayOfWeek, 10);

            var genreRepositoryMock = new Mock <IGenreRepository>();

            genreRepositoryMock.Setup(x => x.GetPercent(It.IsAny <string>(), It.IsAny <DayOfWeek>())).Returns(genrePercentExpected);

            var commandResult = await new AddSaleCommandHandler(saleRepositoryMock.Object, genreRepositoryMock.Object)
                                .Handle(new AddSaleCommand(new List <AddSaleAlbumCommand> {
                new AddSaleAlbumCommand("teste", "pop", 10)
            }), new CancellationToken());

            Assert.NotNull(commandResult);
            Assert.True(commandResult.Id != Guid.Empty);
            Assert.NotEmpty(commandResult.Albums);
        }