Exemplo n.º 1
0
        public async Task Create_Method_Adds_Provided_Order_To_Context()
        {
            var order = OrdersSeed.Orders.Value.FirstOrDefault();

            Assert.NotNull(order);

            using (var scope = this._repoScopeCreate())
            {
                var orderNew = OrderNew.From(order);

                var created = await scope.Repository.Create(orderNew);

                Assert.NotNull(created);
                Assert.True(created.OrderId == orderNew.OrderId);
                Assert.True(created.CustomerName == orderNew.CustomerName);
                Assert.True(created.PostCode == orderNew.PostCode);
                Assert.True(created.HouseNumber == orderNew.HouseNumber);
                Assert.True(created.Price == orderNew.Price);
            }

            using (var scope = this._repoScopeCreate())
            {
                var saved = await scope.Repository.Get(OrderId.FromString(order.OrderId));

                Assert.NotNull(saved);
            }
        }
Exemplo n.º 2
0
        public async Task PaginatedGet_Method_Returns_Paginated_Result_Of_Orders()
        {
            var paging = Paging.Default;

            paging.IncludeTotalCnt = true;

            using (var scope = this._repoScopeCreate())
            {
                foreach (var order in OrdersSeed.Orders.Value)
                {
                    var orderNew = OrderNew.From(order);
                    await scope.Repository.Create(orderNew);
                }
            }

            using (var scope = this._repoScopeCreate())
            {
                var result = await scope.Repository.Get(paging);

                Assert.NotNull(result);
                Assert.True(result.TotalCount == OrdersSeed.Orders.Value.Count);
                Assert.True(result.Skipped == paging.Skip);
                Assert.True(result.Take <= paging.Take);
            }
        }
Exemplo n.º 3
0
        public async Task Delete_Method_Removes_Specified_Order_From_Context()
        {
            var order = OrdersSeed.Orders.Value.FirstOrDefault();

            Assert.NotNull(order);

            var orderNew = OrderNew.From(order);
            var orderId  = OrderId.FromString(orderNew.OrderId);

            using (var scope = this._repoScopeCreate())
            {
                await scope.Repository.Create(orderNew);
            }

            using (var scope = this._repoScopeCreate())
            {
                await scope.Repository.Delete(orderId);
            }

            using (var scope = this._repoScopeCreate())
            {
                var deleted = await scope.Repository.Get(orderId);

                Assert.Null(deleted);
            }
        }
        public void OrderNew_Creates_A_Copy_Of_Provided_Source()
        {
            var copy = OrderNew.From(Source);

            Assert.True(copy != Source);
            Assert.Equal(copy.OrderId, Source.OrderId);
            Assert.Equal(copy.HouseNumber, Source.HouseNumber);
            Assert.Equal(copy.PostCode, Source.PostCode);
            Assert.Equal(copy.Price, Source.Price);
            Assert.Equal(copy.CustomerName, Source.CustomerName);
        }
        public async Task Create_Method_Calls_Create_Method_Of_IOrdersRepository_In_Order_To_Execute_A_Call()
        {
            var order = OrdersSeed.Orders.Value.FirstOrDefault();

            Assert.NotNull(order);

            var orderNew = OrderNew.From(order);

            await Service.Create(orderNew);

            this.Repository.Verify(repository => repository.Create(orderNew), Times.Once);
            this.Repository.VerifyNoOtherCalls();
        }
        public void OrderNew_Creates_A_Copy_Of_Provided_Source_And_Can_Supply_A_Callback_To_Perform_Extra_Actions_On_Copy()
        {
            var updatedName = "Updated";

            var copy = OrderNew.From(Source, order => order.CustomerName = updatedName);

            Assert.True(copy != Source);
            Assert.Equal(copy.OrderId, Source.OrderId);
            Assert.Equal(copy.HouseNumber, Source.HouseNumber);
            Assert.Equal(copy.PostCode, Source.PostCode);
            Assert.Equal(copy.Price, Source.Price);
            Assert.NotEqual(copy.CustomerName, Source.CustomerName);
            Assert.True(copy.CustomerName == updatedName);
        }
Exemplo n.º 7
0
        public async Task Create_Method_Throws_If_Order_With_Provided_Id_Exists_In_Context()
        {
            var order = OrdersSeed.Orders.Value.FirstOrDefault();

            Assert.NotNull(order);

            var orderNew = OrderNew.From(order);

            using (var scope = this._repoScopeCreate())
            {
                await scope.Repository.Create(orderNew);
            }

            using (var scope = this._repoScopeCreate())
            {
                var ex = await Assert.ThrowsAsync <OrderExistsException>(() => scope.Repository.Create(orderNew));

                Assert.True(ex.OrderId == orderNew.OrderId);
            }
        }
Exemplo n.º 8
0
        public override IEnumerable <object[]> GetData(MethodInfo testMethod)
        {
            var validOrder = OrdersSeed.Orders.Value.FirstOrDefault();

            Assert.NotNull(validOrder);

            var orders = new[]
            {
                new [] { OrderNew.From(validOrder, order => { order.CustomerName = new String('A', OrderConstants.CustomerName.MinLength - 1); }) },
                new [] { OrderNew.From(validOrder, order => { order.CustomerName = new String('A', OrderConstants.CustomerName.MaxLength + 1); }) },
                new [] { OrderNew.From(validOrder, order => { order.CustomerName = "N"; }) },
                new [] { OrderNew.From(validOrder, order => { order.PostCode = "12345"; }) },
                new [] { OrderNew.From(validOrder, order => { order.OrderId = "ASFG23124124"; }) },
                new [] { OrderNew.From(validOrder, order => { order.HouseNumber = 0; }) },
                new [] { OrderNew.From(validOrder, order => { order.Price = 0m; }) },
                new IOrderNew[] { new OrderNew() }
            };

            return(orders);
        }
Exemplo n.º 9
0
        public async Task Update_Method_Updates_Specified_Order_And_Returns_Updated_Order()
        {
            var order = OrdersSeed.Orders.Value.FirstOrDefault();

            Assert.NotNull(order);

            var orderNew = OrderNew.From(order);
            var orderId  = OrderId.FromString(orderNew.OrderId);

            using (var scope = this._repoScopeCreate())
            {
                await scope.Repository.Create(orderNew);
            }

            using (var scope = this._repoScopeCreate())
            {
                var orderUpdate = OrderUpdate.From(order, update => update.CustomerName = "New Top Customer");
                var updated     = await scope.Repository.Update(orderId, orderUpdate);

                Assert.NotNull(updated);
                Assert.True(updated.OrderId == orderId.Value);
                Assert.True(updated.CustomerName == orderUpdate.CustomerName);
            }
        }