/*[TestMethod]*/ public void ConvertTest()    //TODO: Fix test
        {
            var s  = GetRandom.Double();
            var s1 = Obj.Convert(s.ToString(UseCulture.Invariant));

            Assert.AreEqual(s.ToString(UseCulture.Invariant), s1.ToString(UseCulture.Invariant));
        }
Ejemplo n.º 2
0
        public async Task WHEN_customer_is_not_authenticated_SHOULD_return_False()
        {
            //Setup
            _container.GetMock <IComposerContext>().SetupGet(mock => mock.IsAuthenticated).Returns(false);

            //Arrange
            var provider = _container.CreateInstance <EditingOrderProvider>();

            var cartShipmentStatuses = new string[] { "Pending" };
            var shipmentList         = cartShipmentStatuses?.Select(status => new Shipment()
            {
                Status            = status,
                Address           = new Address(),
                FulfillmentMethod = new FulfillmentMethod
                {
                    Cost = GetRandom.Double()
                },
                Taxes = new List <Tax>()
            }).ToList();

            var order = CreateOrderWithShipments(shipmentList);

            //Act
            var result = await provider.CanEdit(order).ConfigureAwait(false);

            //Assert
            result.Should().Be(false);
        }
Ejemplo n.º 3
0
        public void ConvertTest()
        {
            var s  = GetRandom.Double();
            var s1 = Obj.Convert(s.ToString(UseCulture.Invariant));

            Assert.AreEqual(s.ToString(UseCulture.Invariant), s1.ToString(UseCulture.Invariant));
        }
Ejemplo n.º 4
0
        public override void IsEqualTest()
        {
            var s = GetRandom.Double();

            Assert.IsFalse(Obj.IsEqual(s));
            Assert.IsTrue(Obj.IsEqual(Obj.Value));
        }
        public void Double_returns_expected_Double_when_minValue_and_maxValue_are_same()
        {
            var expected = GetRandom.Double();
            var actual   = GetRandom.Double(expected, expected);

            actual.ShouldBe(expected);
        }
        [TestMethod] public void IsNotGreaterTest()
        {
            var s = Obj.Value - GetRandom.Double(0, 100);

            Assert.IsFalse(Obj.IsNotGreater(s));
            Assert.IsTrue(Obj.IsNotGreater(Obj.Value));
        }
Ejemplo n.º 7
0
        [TestMethod] public void ToDecimalTest()
        {
            var m = GetRandom.Decimal();
            var d = GetRandom.Double(Convert.ToSingle(decimal.MinValue),
                                     Convert.ToSingle(decimal.MaxValue));
            var f = GetRandom.Float(Convert.ToSingle(decimal.MinValue),
                                    Convert.ToSingle(decimal.MaxValue));
            var l  = GetRandom.Int64();
            var i  = GetRandom.Int32();
            var s  = GetRandom.Int16();
            var b  = GetRandom.Int8();
            var ul = GetRandom.UInt64();
            var ui = GetRandom.UInt32();
            var us = GetRandom.UInt16();
            var ub = GetRandom.UInt8();

            Assert.AreEqual(m, Decimals.ToDecimal(m));
            Assert.AreEqual(Convert.ToDecimal(d), Decimals.ToDecimal(d));
            Assert.AreEqual(Convert.ToDecimal(f), Decimals.ToDecimal(f));
            Assert.AreEqual(Convert.ToDecimal(l), Decimals.ToDecimal(l));
            Assert.AreEqual(Convert.ToDecimal(i), Decimals.ToDecimal(i));
            Assert.AreEqual(Convert.ToDecimal(s), Decimals.ToDecimal(s));
            Assert.AreEqual(Convert.ToDecimal(b), Decimals.ToDecimal(b));
            Assert.AreEqual(Convert.ToDecimal(ul), Decimals.ToDecimal(ul));
            Assert.AreEqual(Convert.ToDecimal(ui), Decimals.ToDecimal(ui));
            Assert.AreEqual(Convert.ToDecimal(us), Decimals.ToDecimal(us));
            Assert.AreEqual(Convert.ToDecimal(ub), Decimals.ToDecimal(ub));
            Assert.AreEqual(1.2345M, Decimals.ToDecimal("1.2345"));
            Assert.AreEqual(1.2345M, Decimals.ToDecimal(1.2345D));
            Assert.AreEqual(1.2345M, Decimals.ToDecimal(1.2345F));
        }
        [TestMethod] public void IsNotEqualTest()
        {
            var s = GetRandom.Double();

            Assert.IsTrue(Obj.IsNotEqual(s));
            Assert.IsFalse(Obj.IsNotEqual(Obj.Value));
        }
Ejemplo n.º 9
0
 protected override void SetRandomValues()
 {
     base.SetRandomValues();
     rate          = GetRandom.Double();
     order_line_id = GetRandom.String();
     type          = GetRandom.String();
 }
Ejemplo n.º 10
0
        [TestMethod] public void RoundTest()
        {
            Func <double, RoundingStrategy, sbyte, byte, double, double> round =
                (x, strategy, percition, digits, step) => {
                var p = new RoundingPolicy(strategy, percition, digits, step);
                switch (p.Strategy)
                {
                case RoundingStrategy.RoundUp: return(Rounding.Up(x, p.Decimals));

                case RoundingStrategy.RoundDown: return(Rounding.Down(x, p.Decimals));

                case RoundingStrategy.RoundUpByStep: return(Rounding.UpByStep(x, p.Step));

                case RoundingStrategy.RoundDownByStep:
                    return(Rounding.DownByStep(x, p.Step));

                case RoundingStrategy.RoundTowardsPositive:
                    return(Rounding.TowardsPositive(x, p.Decimals));

                case RoundingStrategy.RoundTowardsNegative:
                    return(Rounding.TowardsNegative(x, p.Decimals));

                default: return(Rounding.Off(x, p.Decimals, p.Digit));
                }
            };

            Assert.AreEqual(4.5, round(4.45, RoundingStrategy.RoundUp, 1, GetRandom.UInt8(), GetRandom.Double()));
            Assert.AreEqual(-4.45, round(-4.456, RoundingStrategy.RoundDown, 2, GetRandom.UInt8(), GetRandom.Double()));
            Assert.AreEqual(-4.5, round(-4.45, RoundingStrategy.RoundUpByStep, GetRandom.Int8(), GetRandom.UInt8(), 0.25));
            Assert.AreEqual(4.25, round(4.45, RoundingStrategy.RoundDownByStep, GetRandom.Int8(), GetRandom.UInt8(), 0.25));
            Assert.AreEqual(-4.5, round(-4.45, RoundingStrategy.RoundTowardsNegative, 1, GetRandom.UInt8(), GetRandom.Double()));
            Assert.AreEqual(4.46, round(4.456, RoundingStrategy.RoundTowardsPositive, 2, GetRandom.UInt8(), GetRandom.Double()));
            Assert.AreEqual(4.45, round(4.456, RoundingStrategy.Round, 2, 7, GetRandom.Double()));
        }
Ejemplo n.º 11
0
        public async Task WHEN_order_customer_and_context_customer_are_different_SHOULD_return_False()
        {
            //Arrange
            var provider = _container.CreateInstance <EditingOrderProvider>();

            var cartShipmentStatuses = new string[] { "Pending" };
            var shipmentList         = cartShipmentStatuses?.Select(status => new Shipment()
            {
                Status            = status,
                Address           = new Address(),
                FulfillmentMethod = new FulfillmentMethod
                {
                    Cost = GetRandom.Double()
                },
                Taxes = new List <Tax>()
            }).ToList();

            var order = CreateOrderWithShipments(shipmentList);

            order.CustomerId = Guid.NewGuid().ToString();

            //Act
            var result = await provider.CanEdit(order).ConfigureAwait(false);

            //Assert
            result.Should().Be(false);
        }
Ejemplo n.º 12
0
        public async Task WHEN_order_with_provided_shipment_statuses_SHOULD_return_correct_IsOrderEditableAsync(string editableShipmentStates,
                                                                                                                string[] cartShipmentStatuses,
                                                                                                                bool expectedIsOrderEditable)
        {
            //Arrange
            var provider = _container.CreateInstance <EditingOrderProvider>();

            _container.GetMock <IOrderRepository>()
            .Setup(r => r.GetOrderSettings(It.IsAny <string>())).ReturnsAsync(new OrderSettings()
            {
                EditableShipmentStates = editableShipmentStates
            });

            var shipmentList = cartShipmentStatuses?.Select(status => new Shipment()
            {
                Status            = status,
                Address           = new Address(),
                FulfillmentMethod = new FulfillmentMethod
                {
                    Cost = GetRandom.Double()
                },
                Taxes = new List <Tax>()
            }).ToList();

            var order = CreateOrderWithShipments(shipmentList);

            //Act
            var result = await provider.CanEdit(order).ConfigureAwait(false);

            //Assert
            result.Should().Be(expectedIsOrderEditable);
        }
        [TestMethod] public void IsNotLessTest()
        {
            var s = Obj.Value + GetRandom.Double(0, 100);

            Assert.IsFalse(Obj.IsNotLess(s));
            Assert.IsTrue(Obj.IsNotLess(Obj.Value));
        }
Ejemplo n.º 14
0
        public void ValueTests()
        {
            var d = GetRandom.Double();

            obj.Value = d;
            Assert.AreEqual(d, obj.Value);
            Assert.AreEqual(d.ToString(UseCulture.Invariant), obj.ValueAsString);
        }
Ejemplo n.º 15
0
 [TestInitialize] public override void TestInitialize()
 {
     base.TestInitialize();
     unitData = GetRandom.Object <UnitData>();
     unit     = new Unit(unitData);
     amount   = GetRandom.Double(-1000, 1000);
     quantity = new Abc.Domain.Quantity.Quantity(amount, unit);
 }
Ejemplo n.º 16
0
        public void TestProperty(Func <double> get, Action <double> set)
        {
            var s = GetRandom.Double();

            Assert.AreNotEqual(s, get());
            set(s);
            Assert.AreEqual(s, get());
        }
        public void Double_returns_random_Double_less_than_maxValue()
        {
            var maxValue = GetRandom.Double();
            var actual   = GetRandom.Double(maxValue);

            actual.ShouldBeOfType <double>();
            actual.ShouldBeLessThanOrEqualTo(maxValue);
        }
Ejemplo n.º 18
0
 [TestMethod] public void IsPositiveTest()
 {
     Assert.IsTrue(RoundingPolicy.isPositive(GetRandom.Double(0)));
     Assert.IsFalse(RoundingPolicy.isPositive(GetRandom.Double(max: 0)));
     Assert.IsTrue(RoundingPolicy.isPositive(123.456));
     Assert.IsFalse(RoundingPolicy.isPositive(-123.456));
     Assert.IsTrue(RoundingPolicy.isPositive(0));
 }
Ejemplo n.º 19
0
        public void IsGreaterTest()
        {
            var s = Obj.Value;
            var d = GetRandom.Double(0, 100);

            s -= d;
            Assert.IsTrue(Obj.IsGreater(s));
            Assert.IsFalse(Obj.IsGreater(Obj.Value));
        }
Ejemplo n.º 20
0
        public void ValueAsStringTests()
        {
            obj.ValueAsString = GetRandom.String();
            Assert.AreEqual(double.NaN, obj.Value);
            var d = GetRandom.Double();

            obj.ValueAsString = d.ToString(UseCulture.Invariant);
            Assert.AreEqual(d.ToString(UseCulture.Invariant), obj.Value.ToString(UseCulture.Invariant));
        }
        private void TestApproval(Approver approver, double min, double max = double.MaxValue)
        {
            var amount = GetRandom.Double(min, max);
            var p      = new Purchase(number, amount, purpose);

            department.Approve(p, logBook);

            Assert.AreEqual(approver.ApprovalMsg(number, purpose), logBook.ReadLine());
        }
Ejemplo n.º 22
0
        public static Quantity Random()
        {
            var r = new Quantity();

            r.SetRandomValues();
            r.amount = GetRandom.Double();
            r.unit   = GetRandom.String();
            return(r);
        }
        public void Double_returns_random_Double_between_minValue_and_maxValue()
        {
            var maxValue = GetRandom.Double();
            var minValue = GetRandom.Double(maxValue);
            var actual   = GetRandom.Double(minValue, maxValue);

            actual.ShouldBeOfType <double>();
            actual.ShouldBeGreaterThanOrEqualTo(minValue);
            actual.ShouldBeLessThanOrEqualTo(maxValue);
        }
Ejemplo n.º 24
0
        public static Unit Random()
        {
            var n = new BaseUnit();

            n.SetRandomValues();
            n.Measure       = Measure.Random();
            n.Factor        = GetRandom.Double();
            n.SystemOfUnits = GetRandom.String();
            return(n);
        }
        public void WHEN_cart_has_summary_info_SHOULD_map_vm()
        {
            //Arrange
            UseCountryServiceMock();

            var localizationProvider = new Mock <ILocalizationProvider>();

            localizationProvider
            .Setup(l => l.GetLocalizedString(It.IsAny <GetLocalizedParam>()))
            .Returns(GetRandom.String(32))
            .Verifiable();

            Container.Use(localizationProvider);

            var p = new CreateCartViewModelParam()
            {
                Cart = new Overture.ServiceModel.Orders.Cart()
                {
                    TaxTotal      = (decimal)GetRandom.Double(0, 1000),
                    SubTotal      = (decimal)GetRandom.Double(0, 1000),
                    Total         = (decimal)GetRandom.Double(0, 10000),
                    DiscountTotal = (decimal)GetRandom.Double(0, 100),
                    Shipments     = new List <Shipment>()
                    {
                        new Shipment()
                        {
                            Amount = (decimal)GetRandom.PositiveDouble(25)
                        }
                    }
                },
                CultureInfo      = CultureInfo.InvariantCulture,
                BaseUrl          = GetRandom.String(32),
                ProductImageInfo = new ProductImageInfo()
                {
                    ImageUrls = new List <ProductMainImage>()
                }
            };

            var sut = Container.CreateInstance <CartViewModelFactory>();

            //Act
            var vm = sut.CreateCartViewModel(p);

            //Assert
            vm.Should().NotBeNull();
            vm.OrderSummary.Should().NotBeNull();
            vm.OrderSummary.TaxTotal.Should().NotBeNullOrWhiteSpace();
            vm.OrderSummary.SubTotal.Should().NotBeNullOrWhiteSpace();
            vm.OrderSummary.Total.Should().NotBeNullOrWhiteSpace();
            vm.OrderSummary.DiscountTotal.Should().NotBeNullOrWhiteSpace();
            vm.OrderSummary.Shipping.Should().NotBeNullOrWhiteSpace();
        }
        public static Mock <IFulfillmentMethodRepository> MockFulfillmentRepoWithRandomMethods()
        {
            Guid shipmentId = GetRandom.Guid();

            var fulfillmentRepoMock = new Mock <IFulfillmentMethodRepository>();

            fulfillmentRepoMock.Setup(m => m.GetCalculatedFulfillmentMethods(It.IsNotNull <GetShippingMethodsParam>()))
            .ReturnsAsync(new List <FulfillmentMethod>
            {
                new FulfillmentMethod()
                {
                    Id                    = GetRandom.Guid(),
                    Cost                  = GetRandom.Double(0, 30.0),
                    DisplayName           = new LocalizedString(),
                    ExpectedDeliveryDate  = GetRandom.DateTimeFrom(DateTime.Now),
                    FulfillmentMethodType = FulfillmentMethodType.Shipping,
                    Name                  = GetRandom.String(12),
                    ShipmentId            = shipmentId,
                    ShippingProviderId    = GetRandom.Guid(),
                    TaxCategory           = GetRandom.String(12),
                    PropertyBag           = new PropertyBag()
                },
                new FulfillmentMethod()
                {
                    Id                    = GetRandom.Guid(),
                    Cost                  = GetRandom.Double(0, 30.0),
                    DisplayName           = new LocalizedString(),
                    ExpectedDeliveryDate  = GetRandom.DateTimeFrom(DateTime.Now),
                    FulfillmentMethodType = FulfillmentMethodType.Shipping,
                    Name                  = GetRandom.String(12),
                    ShipmentId            = shipmentId,
                    ShippingProviderId    = GetRandom.Guid(),
                    TaxCategory           = GetRandom.String(12),
                    PropertyBag           = new PropertyBag()
                },
                new FulfillmentMethod()
                {
                    Id                    = GetRandom.Guid(),
                    Cost                  = GetRandom.Double(0, 30.0),
                    DisplayName           = new LocalizedString(),
                    ExpectedDeliveryDate  = GetRandom.DateTimeFrom(DateTime.Now),
                    FulfillmentMethodType = FulfillmentMethodType.Shipping,
                    Name                  = GetRandom.String(12),
                    ShipmentId            = shipmentId,
                    ShippingProviderId    = GetRandom.Guid(),
                    TaxCategory           = GetRandom.String(12),
                    PropertyBag           = new PropertyBag()
                }
            });

            return(fulfillmentRepoMock);
        }
Ejemplo n.º 27
0
        internal static LineItem CreateLineItem(IList <LineItem> lineItems, IList <Reward> rewards, bool withRewards, IList <ProductMainImage> images)
        {
            var lineItem = new LineItem()
            {
                Id             = GetRandom.Guid(),
                ProductId      = GetRandom.String(7),
                ProductSummary = new CartProductSummary()
                {
                    DisplayName = GetRandom.String(12)
                },
                VariantId    = GetRandom.String(7),
                CurrentPrice = (decimal)GetRandom.PositiveDouble(1000),
                DefaultPrice = (decimal)GetRandom.PositiveDouble(2000),
                Quantity     = GetRandom.Double(1, 15),
                Total        = (decimal)GetRandom.PositiveDouble(10000)
            };

            if (withRewards)
            {
                var reward = CreateRandomReward(rewards, RewardLevel.LineItem);

                lineItem.Rewards = new List <Reward>()
                {
                    reward,
                    CreateRandomReward(rewards, RewardLevel.LineItem),
                    CreateRandomReward(rewards, RewardLevel.LineItem),
                    CreateRandomReward(rewards, RewardLevel.LineItem),
                    reward
                };
            }

            if (images != null)
            {
                var img = new ProductMainImage()
                {
                    ImageUrl         = GetRandom.WwwUrl(),
                    FallbackImageUrl = GetRandom.WwwUrl(),
                    ProductId        = lineItem.ProductId,
                    VariantId        = lineItem.VariantId
                };

                images.Add(img);
            }

            if (lineItems != null)
            {
                lineItems.Add(lineItem);
            }

            return(lineItem);
        }
Ejemplo n.º 28
0
        public void Double_should_return_a_correct_value()
        {
            var          sut      = new GetRandom();
            const double minValue = 5.78;
            const double maxValue = 100.65;

            var generatedValues = new List <double>();

            1000.Times(_ => generatedValues.Add(sut.Double(minValue, maxValue)));

            generatedValues.Min().ShouldBeGreaterThanOrEqualTo(minValue);
            generatedValues.Max().ShouldBeLessThanOrEqualTo(maxValue);
            generatedValues.GroupBy(x => x).Count().ShouldBe(1000);
        }
Ejemplo n.º 29
0
        public void RoundTest()
        {
            var d = GetRandom.Double();
            var roundingPolicy = new testRoundingPolicy(d);

            obj = quantity;
            var q = obj.Round(roundingPolicy);

            Assert.IsNotNull(q);
            Assert.AreNotEqual(q, obj);
            Assert.AreNotSame(q, obj);
            Assert.AreEqual(d, q.Amount);
            Assert.AreNotSame(q.Unit, obj.Unit);
            arePropertiesEqual(q.Unit.Data, obj.Unit.Data);
        }
Ejemplo n.º 30
0
        private void AddNewStreams(ChronoEventArgs chronoArgs)
        {
            _runningDelta += chronoArgs.Delta;

            if (_runningDelta >= NEW_STREAM_CHECK_FREQUENCY)
            {
                var outcome = GetRandom.Double(0, _runningDelta);
                var chance  = _chanceOfNewStream;
                while (streams.Count <= _maximumStreams && outcome < chance)
                {
                    chance -= NEW_STREAM_CHECK_FREQUENCY;
                    AddNewGlyphStream();
                }

                _runningDelta -= NEW_STREAM_CHECK_FREQUENCY;
            }
        }