コード例 #1
0
        public async Task Should_Get_User_By_Id()
        {
            // Arrange
            User expectedUser = FakeUsers.LockedOutUser;
            var  query        = new Details.Query(expectedUser.Id);

            // Act
            User user = await _handler.Handle(query, new CancellationToken());

            // Assert
            user.Should().BeEquivalentTo(expectedUser, opt => opt.Excluding(u => u.ConcurrencyStamp));
        }
コード例 #2
0
ファイル: DetailsTests.cs プロジェクト: laimis/stock-analysis
        public async Task Get_WorksAsync()
        {
            var(storage, opt) = _fixture.CreateStorageWithSoldOption();

            var query = new Details.Query {
                Id = opt.State.Id
            };

            var mock = new Mock <IStocksService2>();

            mock.Setup(x => x.GetPrice(opt.State.Ticker))
            .Returns(Task.FromResult(
                         new StockServiceResponse <core.Price>(
                             new core.Price(100)
                             )
                         ));

            query.WithUserId(opt.State.UserId);

            var handler = new Details.Handler(storage, mock.Object);

            var result = await handler.Handle(query, CancellationToken.None);

            Assert.NotNull(result);
        }
コード例 #3
0
        public async Task Should_Return_Rest_Exception_If_Null()
        {
            var context = GetDbContext();

            var sut = new Details.Handler(context, _mapper);

            await Assert.ThrowsAsync <RestException>(() => sut.Handle(new Details.Query(1), CancellationToken.None));
        }
コード例 #4
0
        public async Task Handle_CallsFindByIdAsyncWithValidGuid_ReturnsTrailForGivenId()
        {
            //Arrange
            var id = Guid.Parse("08489d16-d7b1-4a90-8bef-0b4c94b50fe0");

            trailServiceMock.Setup(x => x.FindByIdAsync(id)).ReturnsAsync(TrailsMockData.TrailByIdMock);

            var validGuidRequest = new Details.Query()
            {
                Id = id
            };
            var cancellationToken = new CancellationToken();

            //Act
            Trail trail = await detailsHandler.Handle(validGuidRequest, cancellationToken);

            //Assert
            trailServiceMock.Verify(x => x.FindByIdAsync(id), Times.Once);
            Assert.IsType <Trail>(trail);
            Assert.Equal("Trail By Id", trail.Name);
        }
コード例 #5
0
        public void GivenAnOrderViewOrderDetails()
        {
            using var factory = new DbContextFactory <ShopContext>();
            var options = factory.CreateOptions();

            using var context = factory.CreateContext(options);

            var createProductHandler = new Features.Products.Create.Handler(context);
            var foo = createProductHandler.Handle(new Features.Products.Create.Command {
                Code = "Foo", Description = "Foo description"
            }, default).Result;
            var bar = createProductHandler.Handle(new Features.Products.Create.Command {
                Code = "Bar", Description = "Bar description"
            }, default).Result;

            // Create an order
            var createCommand = new Create.Command
            {
                DateCreated = new DateTime(2019, 1, 1),
                Lines       = new List <Create.Command.OrderLine>
                {
                    new Create.Command.OrderLine {
                        ProductCode = foo, Quantity = 1
                    },
                    new Create.Command.OrderLine {
                        ProductCode = bar, Quantity = 3
                    },
                }
            };
            var createHandler = new Create.Handler(context);
            var orderNumber   = createHandler.Handle(createCommand, default).Result;

            // View order details
            var query = new Details.Query {
                Number = orderNumber
            };
            var detailsHandler = new Details.Handler(context);
            var orderDetails   = detailsHandler.Handle(query, default).Result;

            Assert.AreEqual(createCommand.DateCreated, orderDetails.CreatedDate);
            Assert.AreEqual(createCommand.Lines.Count(), orderDetails.Lines.Count());
            foreach (var(line, index) in orderDetails.Lines.Select((l, i) => (l, i)))
            {
                var orderLine       = createCommand.Lines.Single(x => x.ProductCode == line.ProductCode);
                var orderLineNumber = index + 1;
                Assert.AreEqual(orderLineNumber, line.Number);
                Assert.AreEqual(orderLine.Quantity, line.Quantity);
            }
        }
コード例 #6
0
        public async Task Should_Get_Details()
        {
            // Arrange
            Appointment appointment = AppointmentSeedData.RockingXMasConcert;

            _arpaContext.FindAsync <Appointment>(Arg.Any <object[]>(), Arg.Any <CancellationToken>())
            .Returns(appointment);

            // Act
            Appointment result = await _handler
                                 .Handle(new Details.Query <Appointment>(Guid.NewGuid()), new CancellationToken());

            // Assert
            result.Should().BeEquivalentTo(appointment);
        }
コード例 #7
0
        public void GetJobDetails_WithEmptyJobId_ShouldThrowException()
        {
            //Arrange
            var query = new Details.Query {
                Id = 0
            };
            var handler = new Details.Handler(testContext, testMapper);
            //Assert
            var ex = Assert.CatchAsync <Exception>(() => handler.Handle(query, CancellationToken.None));

            if (ex.Equals(typeof(RestException)))
            {
                Assert.That(ex.Message, Is.EqualTo("Not Found"));
            }
        }
コード例 #8
0
        public void SearchByInvalidCartIdShouldThrowRestException()
        {
            using (var context = GetDbContext())
            {
                //arrange
                InitDatabaseTablesForOrderTests(context);
                var command = new Details.Query()
                {
                    CartId = "1234-5678-0000-3333"
                };
                var handler = new Details.Handler(context);

                //assert
                Assert.ThrowsExceptionAsync <RestException>(() => handler.Handle(command, (new CancellationTokenSource()).Token));
            }
        }
コード例 #9
0
        public void Should_get_details()
        {
            var context = GetDbContext();

            context.Activities.Add(new Activity {
                Id = 1, Title = "Test Activity 1"
            });
            context.Activities.Add(new Activity {
                Id = 2, Title = "Test Activity 2"
            });
            context.SaveChanges();

            var sut    = new Details.Handler(context, _mapper);
            var result = sut.Handle(new Details.Query(1), CancellationToken.None).Result;

            Assert.Equal("Test Activity 1", result.Title);
        }
コード例 #10
0
        public void ListHandler_NullQuery_ShouldThrowArgumentNullException()
        {
            var token = new CancellationTokenSource().Token;

            _query.Id = new Guid("d9d10414-f86a-4bba-929e-237e1f890e26");
            using (var context = new ExpenseTrackerDbContext(_options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                _detailsHandler = new Details.Handler(context, _mapper);

                var action = _detailsHandler.Handle(_query, token);

                Assert.ThrowsAsync <ArgumentNullException>(() => action);
            }
        }
コード例 #11
0
        public async Task SearchByValidCartIdShouldReturnOrder()
        {
            using (var context = GetDbContext())
            {
                //arrange
                InitDatabaseTablesForOrderTests(context);
                var command = new Details.Query()
                {
                    CartId = "1234-5678-0000-1111"
                };
                var handler = new Details.Handler(context);

                //act
                var order = await handler.Handle(command, (new CancellationTokenSource()).Token);

                //assert
                Assert.IsTrue(order.CartId == "1234-5678-0000-1111" && order.OrderDetails.Count() == 3 && order.Id == 1);
            }
        }
コード例 #12
0
        public void GetJobDetails_WithValidJobId_ShouldGetJobDetails()
        {
            //Arrange
            var query = new Details.Query {
                Id = 1
            };
            var detailsHandler = new Details.Handler(testContext, testMapper);
            //Act
            var detailsResult = detailsHandler.Handle(query, CancellationToken.None).Result;

            //Assert
            Assert.NotNull(detailsResult);
            Assert.That(detailsResult.JobName, Is.EqualTo("TestJob1"));
            Assert.That(detailsResult.Company, Is.EqualTo("Netapp"));
            Assert.That(detailsResult.Replication, Is.EqualTo("Zerto"));
            Assert.That(detailsResult.Servers, Is.EqualTo("7"));
            Assert.That(detailsResult.RTA, Is.EqualTo("10"));
            Assert.That(detailsResult.Results, Is.EqualTo("OK"));
            Assert.That(detailsResult.Key, Is.EqualTo("AAAA-BBBB-CCCC-DDDD"));
            Assert.That(detailsResult.RTONeeded, Is.EqualTo("20"));
        }
コード例 #13
0
        public void DetailsHandler_GetRecord_GetExpenseDetails()
        {
            var token = new CancellationTokenSource().Token;

            _query.Id = new Guid("d9d10414-f86a-4bba-929e-237e1f890e26");

            using (var context = new ExpenseTrackerDbContext(_options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();
                SeedTest.SeedData(context);

                _detailsHandler = new Details.Handler(context, _mapper);

                var query    = _detailsHandler.Handle(_query, token).Result;
                var actual   = query;
                var expected = _expenseDto;

                Assert.Equal(expected.Id, actual.Id);
            }
        }