public async Task WHEN_scope_is_null_or_has_no_currency_SHOULD_return_null(bool nullCurrency)
        {
            //Arrange
            var param = new GetScopeCurrencyParam
            {
                Scope       = GetRandom.String(7),
                CultureInfo = CultureInfo.InvariantCulture
            };

            if (nullCurrency)
            {
                _container.GetMock <IScopeRepository>()
                .Setup(repo => repo.GetScopeAsync(It.IsAny <GetScopeParam>()))
                .ReturnsAsync(new Overture.ServiceModel.Scope
                {
                    Currency = null
                });
            }
            else
            {
                _container.GetMock <IScopeRepository>()
                .Setup(repo => repo.GetScopeAsync(It.IsAny <GetScopeParam>()))
                .ReturnsAsync(null);
            }

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

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

            //Assert
            vm.Should().BeNull();
        }
        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);
        }
        public void WHEN_param_is_ok_SHOULD_invoke_ScopeRepo_with_scope_in_param()
        {
            //Arrange
            var param = new GetScopeCurrencyParam
            {
                Scope       = GetRandom.String(7),
                CultureInfo = CultureInfo.InvariantCulture
            };

            _container.GetMock <IScopeRepository>().Setup(scopeRepo => scopeRepo.GetScopeAsync(It.IsNotNull <GetScopeParam>()))
            .Returns((GetScopeParam req) =>
            {
                if (req.Scope != param.Scope)
                {
                    throw new ArgumentException("Scope in param is not passed to the repository.");
                }

                return(Task.FromResult <Overture.ServiceModel.Scope>(null));
            });

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

            //Act & Assert
            Assert.DoesNotThrowAsync(() => sut.GetScopeCurrencyAsync(param));
        }
        public void WHEN_param_is_null_SHOULD_throw_ArgumentNullException_with_param_name()
        {
            //Arrange
            GetScopeCurrencyParam param = null;
            var sut = _container.CreateInstance <ScopeViewService>();

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

            ex.ParamName.Should().NotBeNullOrWhiteSpace();
        }
        public void WHEN_cultureInfo_is_null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var param = new GetScopeCurrencyParam
            {
                Scope       = GetRandom.String(7),
                CultureInfo = null
            };
            var sut = _container.CreateInstance <ScopeViewService>();

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

            ex.ParamName.Should().Be(nameof(param.CultureInfo));
        }
        public void WHEN_scope_is_invalid_SHOULD_throw_ArgumentException_with_paramName(string scope)
        {
            //Arrange
            GetScopeCurrencyParam param = new GetScopeCurrencyParam
            {
                Scope       = scope,
                CultureInfo = CultureInfo.InvariantCulture
            };
            var sut = _container.CreateInstance <ScopeViewService>();

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

            ex.ParamName.Should().Be(nameof(param.Scope));
        }
        public async Task WHEN_param_is_ok_SHOULD_invoke_scopeRepository()
        {
            //Arrange
            var param = new GetScopeCurrencyParam
            {
                Scope       = GetRandom.String(7),
                CultureInfo = CultureInfo.InvariantCulture
            };
            var sut = _container.CreateInstance <ScopeViewService>();

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

            //Assert
            _container.GetMock <IScopeRepository>().Verify(scopeRepo => scopeRepo.GetScopeAsync(It.IsNotNull <GetScopeParam>()));
        }
        public void WHEN_cultureInfo_is_null_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var param = new GetScopeCurrencyParam
            {
                Scope       = GetRandom.String(7),
                CultureInfo = null
            };
            var sut = _container.CreateInstance <ScopeViewService>();

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

            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNull(nameof(param.CultureInfo)));
        }
        public void WHEN_scope_is_invalid_SHOULD_throw_ArgumentException_with_paramName(string scope)
        {
            //Arrange
            GetScopeCurrencyParam param = new GetScopeCurrencyParam
            {
                Scope       = scope,
                CultureInfo = CultureInfo.InvariantCulture
            };
            var sut = _container.CreateInstance <ScopeViewService>();

            //Act & Assert
            Expression <Func <Task <CurrencyViewModel> > > expression = () => sut.GetScopeCurrencyAsync(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)));
        }
        public async Task WHEN_param_is_ok_and_scope_has_currency_SHOULD_invoke_ViewModelMapper()
        {
            //Arrange
            var param = new GetScopeCurrencyParam
            {
                Scope       = GetRandom.String(7),
                CultureInfo = CultureInfo.InvariantCulture
            };

            _container.GetMock <IViewModelMapper>()
            .Setup(vmm => vmm.MapTo <CurrencyViewModel>(It.IsAny <object>(), It.IsNotNull <CultureInfo>()))
            .Verifiable();

            MockScopeRepository();

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

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

            //Assert
            _container.Verify <IViewModelMapper>();
        }
        public async Task WHEN_scope_has_currency_SHOULD_return_viewModel_from_mapper()
        {
            //Arrange
            var param = new GetScopeCurrencyParam
            {
                Scope       = GetRandom.String(7),
                CultureInfo = CultureInfo.InvariantCulture
            };

            var result = new CurrencyViewModel();

            MockScopeRepository();
            _container.GetMock <IViewModelMapper>()
            .Setup(vmm => vmm.MapTo <CurrencyViewModel>(It.IsAny <object>(), It.IsNotNull <CultureInfo>()))
            .Returns(result);

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

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

            //Assert
            vm.Should().Be(result);
        }