Exemple #1
0
        [Ignore("")]//todo: add a nice comment
        //todo: create a functional / integration test
        public async Task WHEN_requested_many_times_SHOULD_invoke_OvertureClient_once()
        {
            //Arrange
            var param = new GetScopeParam
            {
                Scope = GetRandom.String(7)
            };

            MockOvertureClient(param.Scope);
            var sut = _container.CreateInstance <ScopeRepository>();

            //Act
            await sut.GetScopeAsync(param);

            await sut.GetScopeAsync(param);

            await sut.GetScopeAsync(param);

            await sut.GetScopeAsync(param);

            await sut.GetScopeAsync(param);

            //Assert
            _container.GetMock <IOvertureClient>().Verify(client => client.SendAsync(It.IsNotNull <GetScopeRequest>()), Times.AtMostOnce);
        }
        public virtual async Task <CurrencyViewModel> GetScopeCurrencyAsync(GetScopeCurrencyParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException(GetMessageOfNullWhiteSpace(nameof(param.Scope)), nameof(param));
            }
            if (param.CultureInfo == null)
            {
                throw new ArgumentException(GetMessageOfNull(nameof(param.CultureInfo)), nameof(param));
            }

            var p = new GetScopeParam
            {
                Scope = param.Scope
            };

            var scope = await ScopeRepository.GetScopeAsync(p).ConfigureAwait(false);

            CurrencyViewModel vm = null;

            if (scope?.Currency != null)
            {
                vm = ViewModelMapper.MapTo <CurrencyViewModel>(scope.Currency, param.CultureInfo);
            }

            return(vm);
        }
        /// <summary>
        /// Obtains a scope description from Overture including the currency of the scope, but not its children.
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public virtual Task <Scope> GetScopeAsync(GetScopeParam param)
        {
            if (param == null)
            {
                throw new ArgumentNullException(nameof(param));
            }
            if (string.IsNullOrWhiteSpace(param.Scope))
            {
                throw new ArgumentException("Scope is required", nameof(param.Scope));
            }

            var key = new CacheKey(CacheConfigurationCategoryNames.Scopes, param.Scope);

            var scope = CacheProvider.GetOrAddAsync(key, async() =>
            {
                var req = new GetScopeRequest
                {
                    ScopeId         = param.Scope,
                    IncludeCurrency = true,
                    IncludeChildren = false,
                    CultureName     = null
                };

                var response = await OvertureClient.SendAsync(req).ConfigureAwait(false);
                return(response);
            });

            return(scope);
        }
Exemple #4
0
        public void WHEN_param_is_null_SHOULD_throw_ArgumentNullException_with_param_name()
        {
            //Arrange
            GetScopeParam param = null;
            var           sut   = _container.CreateInstance <ScopeRepository>();

            //Act & Assert
            var ex = Assert.ThrowsAsync <ArgumentNullException>(() => sut.GetScopeAsync(param));

            ex.ParamName.Should().NotBeNullOrWhiteSpace();
        }
 private void InitializeScopeItem()
 {
     if (_scopeItem == null)
     {
         var p = new GetScopeParam
         {
             Scope = Scope
         };
         _scopeItem = ScopeRepository.GetScopeAsync(p).ConfigureAwait(false).GetAwaiter().GetResult();
     }
 }
Exemple #6
0
        public void WHEN_request_is_ok_SHOULD_invoke_OvertureClient_with_valid_request()
        {
            //Arrange
            var param = new GetScopeParam
            {
                Scope = GetRandom.String(7)
            };

            MockOvertureClient(param.Scope);
            var sut = _container.CreateInstance <ScopeRepository>();

            //Act & Assert
            Assert.DoesNotThrowAsync(() => sut.GetScopeAsync(param));
        }
Exemple #7
0
        public void WHEN_scope_is_invalid_SHOULD_throw_ArgumentException_with_param_name(string scope)
        {
            //Arrange
            var param = new GetScopeParam
            {
                Scope = scope
            };

            var sut = _container.CreateInstance <ScopeRepository>();

            //Act & Assert
            var ex = Assert.ThrowsAsync <ArgumentException>(() => sut.GetScopeAsync(param));

            ex.ParamName.Should().Be(nameof(param.Scope));
            ex.Message.Should().NotBeNullOrWhiteSpace();
        }
Exemple #8
0
        public async Task WHEN_request_is_ok_SHOULD_invoke_OvertureClient()
        {
            //Arrange
            var param = new GetScopeParam
            {
                Scope = GetRandom.String(7)
            };

            MockOvertureClient(param.Scope);
            var sut = _container.CreateInstance <ScopeRepository>();

            //Act
            var vm = await sut.GetScopeAsync(param);

            //Assert
            _container.GetMock <IOvertureClient>().VerifyAll();
        }
Exemple #9
0
        public void WHEN_scope_is_invalid_SHOULD_throw_ArgumentException_with_param_name(string scope)
        {
            //Arrange
            var param = new GetScopeParam
            {
                Scope = scope
            };

            var sut = _container.CreateInstance <ScopeRepository>();

            //Act & Assert
            Expression <Func <Task <Scope> > > expression = () => sut.GetScopeAsync(param);
            var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke());

            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.Scope)));
        }
Exemple #10
0
        public async Task WHEN_request_is_ok_SHOULD_return_OvertureClient_value()
        {
            //Arrange
            var param = new GetScopeParam
            {
                Scope = GetRandom.String(7)
            };

            var response = new Scope
            {
                Id = Guid.NewGuid().ToString()
            };

            MockOvertureClient(param.Scope, response);
            var sut = _container.CreateInstance <ScopeRepository>();

            //Act
            var res = await sut.GetScopeAsync(param);

            //Assert
            res.Should().Be(response);
        }