コード例 #1
0
        public async Task CanIncludeMostRecentJuncture_Success()
        {
            var           productId       = Guid.NewGuid();
            const decimal mostRecentPrice = 10.00m;

            var product = new Product {
                Id               = productId,
                Name             = "MacBook Pro",
                Code             = "XYZ",
                Created          = UtcNow,
                LastModified     = UtcNow,
                ProductJunctures = new List <ProductJuncture> {
                    new ProductJuncture {
                        Price = 11.95m, Juncture = UtcNow.AddDays(-1)
                    },
                    new ProductJuncture {
                        Price = mostRecentPrice, Juncture = UtcNow
                    },
                    new ProductJuncture {
                        Price = 10.95m, Juncture = UtcNow.AddDays(-4)
                    },
                }
            };

            InitializeData(new Product[] { product });

            var response = await Service.GetByIdAsync(productId);

            Assert.Equal(product.Name, response.Name);
            Assert.Equal(product.Code, response.Code);
            Assert.Equal(product.Created, response.Created);
            Assert.Equal(product.LastModified, response.LastModified);

            Assert.Equal(mostRecentPrice, response.Price);
        }
コード例 #2
0
        public void get_delivery_delay_should_return_when_minus_now()
        {
            // arrange
            var tomorrow = UtcNow.AddDays(1d);
            var options  = new SendOptions().DoNotDeliverBefore(tomorrow);

            // act
            var delay = options.GetDeliveryDelay();

            // assert
            delay.Should().BeLessOrEqualTo(FromDays(1d));
        }
コード例 #3
0
        public void get_delivery_time_should_return_when()
        {
            // arrange
            var tomorrow = UtcNow.AddDays(1d);
            var options  = new SendOptions().DoNotDeliverBefore(tomorrow);

            // act
            var deliveryTime = options.GetDeliveryTime();

            // assert
            deliveryTime.Should().Be(tomorrow);
        }
コード例 #4
0
        protected virtual bool VerifyTwoFactorAuthToken(UserAccount account, string token)
        {
            if (account == null)
            {
                throw new ArgumentNullException(nameof(account));
            }

            _logger.LogInformation(GetLogMessage($"called for accountID: {account.UserId}"));

            if (account.AccountTwoFactorAuthMode != TwoFactorAuthMode.Mobile)
            {
                _logger.LogError(GetLogMessage("AccountTwoFactorAuthMode is not mobile"));
                return(false);
            }

            if (string.IsNullOrWhiteSpace(token))
            {
                _logger.LogError(GetLogMessage("failed -- no token"));
                return(false);
            }

            token = _crypto.Hash(token);

            var expiration  = UtcNow.AddDays(Settings.TwoFactorAuthTokenDurationDays);
            var removequery =
                from t in account.TwoFactorAuthTokenCollection
                where
                t.Issued < account.PasswordChanged ||
                t.Issued < account.MobilePhoneNumberChanged ||
                t.Issued < expiration
                select t;
            var itemsToRemove = removequery.ToArray();

            _logger.LogInformation(GetLogMessage($"number of stale tokens being removed: {itemsToRemove.Length}"));

            foreach (var item in itemsToRemove)
            {
                account.RemoveTwoFactorAuthToken(item);
            }

            var matchquery =
                from t in account.TwoFactorAuthTokenCollection.ToArray()
                where _crypto.VerifyHash(token, t.Token)
                select t;

            var result = matchquery.Any();

            _logger.LogInformation(GetLogMessage($"result was token verified: {result}"));

            return(result);
        }
コード例 #5
0
        public async Task InvalidConcurrencyCannotUpdate_Failure()
        {
            var productId = Guid.NewGuid();

            InitializeData(new Product[]
            {
                new Product {
                    Id = productId, Name = "MacBook Pro", Code = "XYZ", Created = UtcNow, LastModified = UtcNow
                }
            });

            var product = new Product {
                Id = productId, Name = "iMac", Code = "ABC", Created = UtcNow, LastModified = UtcNow.AddDays(1)
            };

            await Assert.ThrowsAsync <DbUpdateConcurrencyException>(() =>
            {
                return(Service.UpdateAsync(product));
            });
        }