Exemplo n.º 1
0
        private static void SetSnapshotApprovalStatus()
        {
            using (new SampleMethodScope())
            {
                var container = new CsrSheila().Context.ShopsContainer();

                var snapshotDate = DateTimeOffset.Now.AddDays(30);
                var result       = Proxy.DoCommand(container.AddPriceSnapshot(_cardFriendlyId, snapshotDate));
                result.Messages.Should().NotContainErrors();
                result.Models.OfType <PriceSnapshotAdded>().FirstOrDefault().Should().NotBeNull();
                var snapshotId = result.Models.OfType <PriceSnapshotAdded>().FirstOrDefault()?.PriceSnapshotId;

                result = Proxy.DoCommand(Container.AddPriceTier(_cardFriendlyId, snapshotId, "USD", 3, 13));
                result.Messages.Should().NotContainErrors();
                result.Models.OfType <PriceTierAdded>().FirstOrDefault().Should().NotBeNull();

                result = Proxy.DoCommand(
                    container.SetPriceSnapshotsApprovalStatus(
                        _cardFriendlyId,
                        new List <string> {
                    snapshotId
                },
                        "ReadyForApproval",
                        "my comment"));
                result.Messages.Should().NotContainErrors();
                result.Messages.Any(m => m.Code.Equals("information", StringComparison.OrdinalIgnoreCase))
                .Should()
                .BeTrue();
            }
        }
Exemplo n.º 2
0
        private static void SetSnapshotApprovalStatus()
        {
            Console.WriteLine("Begin SetSnapshotApprovalStatusUX");

            var container = new CsrSheila().Context.ShopsContainer();

            var result = Proxy.DoCommand(container.AddPriceCard(BookId, "consoleapprovalpricecard", "displayname", "description"));

            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            var cardFriendlyId = result.Models.OfType <PriceCardAdded>().FirstOrDefault()?.PriceCardFriendlyId;

            cardFriendlyId.Should().NotBeNullOrEmpty();
            var cardId = $"Entity-PriceCard-{cardFriendlyId}";

            var snapshotDate = DateTimeOffset.Now.AddDays(3);

            result = Proxy.DoCommand(container.AddPriceSnapshot(cardId, snapshotDate));
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            var snapshotId = result.Models.OfType <PriceSnapshotAdded>().FirstOrDefault()?.PriceSnapshotId;

            result = Proxy.DoCommand(ShopsContainer.AddPriceTier(cardId, snapshotId, "USD", 3, 13));
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            result.Models.OfType <PriceTierAdded>().FirstOrDefault().Should().NotBeNull();

            // REQUEST APPROVAL
            var view = Proxy.GetValue(container.GetEntityView(cardId, "SetSnapshotApprovalStatus", "RequestSnapshotApproval", snapshotId));

            view.Should().NotBeNull();
            view.Policies.Should().BeEmpty();
            view.Properties.Should().NotBeEmpty();
            view.ChildViews.Should().BeEmpty();
            view.Properties.FirstOrDefault(p => p.Name.Equals("Comment")).Value = "request approval comment";
            result = Proxy.DoCommand(container.DoAction(view));
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            result.Messages.Any(m => m.Code.Equals("information", StringComparison.OrdinalIgnoreCase)).Should().BeTrue();

            var card     = Pricing.GetPriceCard(cardFriendlyId);
            var snapshot = card.Snapshots.FirstOrDefault(s => s.Id.Equals(snapshotId, StringComparison.OrdinalIgnoreCase));

            snapshot.Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault().Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault()?.Status.Should().Be("ReadyForApproval");

            // REJECT
            view = Proxy.GetValue(container.GetEntityView(cardId, "SetSnapshotApprovalStatus", "RejectSnapshot", snapshotId));
            view.Should().NotBeNull();
            view.Policies.Should().BeEmpty();
            view.Properties.Should().NotBeEmpty();
            view.ChildViews.Should().BeEmpty();
            view.Properties.FirstOrDefault(p => p.Name.Equals("Comment")).Value = "reject comment";
            result = Proxy.DoCommand(container.DoAction(view));
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            result.Messages.Any(m => m.Code.Equals("information", StringComparison.OrdinalIgnoreCase)).Should().BeTrue();

            card     = Pricing.GetPriceCard(cardFriendlyId);
            snapshot = card.Snapshots.FirstOrDefault(s => s.Id.Equals(snapshotId, StringComparison.OrdinalIgnoreCase));
            snapshot.Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault().Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault()?.Status.Should().Be("Draft");

            view = Proxy.GetValue(ShopsContainer.GetEntityView(cardId, "SetSnapshotApprovalStatus", "RequestSnapshotApproval", snapshotId));
            view.Properties.FirstOrDefault(p => p.Name.Equals("Comment")).Value = "request approval second time comment";
            result = Proxy.DoCommand(container.DoAction(view));
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            result.Messages.Any(m => m.Code.Equals("information", StringComparison.OrdinalIgnoreCase)).Should().BeTrue();

            // APPROVE
            view = Proxy.GetValue(container.GetEntityView(cardId, "SetSnapshotApprovalStatus", "ApproveSnapshot", snapshotId));
            view.Should().NotBeNull();
            view.Policies.Should().BeEmpty();
            view.Properties.Should().NotBeEmpty();
            view.ChildViews.Should().BeEmpty();
            view.Properties.FirstOrDefault(p => p.Name.Equals("Comment")).Value = "approve comment";
            result = Proxy.DoCommand(container.DoAction(view));
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            result.Messages.Any(m => m.Code.Equals("information", StringComparison.OrdinalIgnoreCase)).Should().BeTrue();

            card     = Pricing.GetPriceCard(cardFriendlyId);
            snapshot = card.Snapshots.FirstOrDefault(s => s.Id.Equals(snapshotId, StringComparison.OrdinalIgnoreCase));
            snapshot.Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault().Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault()?.Status.Should().Be("Approved");

            // RETRACT
            view = Proxy.GetValue(container.GetEntityView(cardId, "SetSnapshotApprovalStatus", "RetractSnapshot", snapshotId));
            view.Should().NotBeNull();
            view.Policies.Should().BeEmpty();
            view.Properties.Should().NotBeEmpty();
            view.ChildViews.Should().BeEmpty();
            view.Properties.FirstOrDefault(p => p.Name.Equals("Comment")).Value = "retract comment";
            result = Proxy.DoCommand(container.DoAction(view));
            result.Messages.Any(m => m.Code.Equals("error", StringComparison.OrdinalIgnoreCase)).Should().BeFalse();
            result.Messages.Any(m => m.Code.Equals("information", StringComparison.OrdinalIgnoreCase)).Should().BeTrue();

            card     = Pricing.GetPriceCard(cardFriendlyId);
            snapshot = card.Snapshots.FirstOrDefault(s => s.Id.Equals(snapshotId, StringComparison.OrdinalIgnoreCase));
            snapshot.Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault().Should().NotBeNull();
            snapshot?.SnapshotComponents.OfType <ApprovalComponent>().FirstOrDefault()?.Status.Should().Be("Draft");
        }