コード例 #1
0
        public async void SetDefaultAsync_Publish_Ok()
        {
            // arrange
            const string clientId = "me";
            const string country  = "uk";

            bool published = false;

            WelcomeRegulationRule rule1 = Create("1", "reg_1", null, true, 100);

            _clientRegulationRepositoryMock.Setup(o => o.GetByClientIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <ClientRegulation>());

            _welcomeRegulationRuleRepositoryMock.Setup(o => o.GetByCountryAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <WelcomeRegulationRule>
            {
                rule1
            });

            _clientRegulationPublisherMock.Setup(o => o.PublishAsync(It.IsAny <ClientRegulationsMessage>()))
            .Returns(Task.CompletedTask)
            .Callback(() => published = true);

            // act
            await _service.SetDefaultAsync(clientId, country);

            // assert
            Assert.True(published);
        }
コード例 #2
0
        public async void SetDefaultAsync_Choose_Regulation_Rule_With_Most_Priority()
        {
            // arrange
            const string clientId = "me";
            const string country  = "uk";

            WelcomeRegulationRule rule1 = Create("1", "reg_1", country, true, 10);
            WelcomeRegulationRule rule2 = Create("2", "reg_2", country, true, 100);

            IClientRegulation result = null;

            _clientRegulationRepositoryMock.Setup(o => o.GetByClientIdAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <ClientRegulation>());

            _clientRegulationRepositoryMock.Setup(o => o.AddAsync(It.IsAny <IClientRegulation>()))
            .Returns(Task.CompletedTask)
            .Callback((IClientRegulation o) => result = o);

            _welcomeRegulationRuleRepositoryMock.Setup(o => o.GetByCountryAsync(It.IsAny <string>()))
            .ReturnsAsync(new List <WelcomeRegulationRule>
            {
                rule1,
                rule2
            });

            // act
            await _service.SetDefaultAsync(clientId, country);

            // assert
            Assert.NotNull(result);
            Assert.Equal(result.RegulationId, rule2.RegulationId);
            Assert.Equal(result.Active, rule2.Active);
        }
コード例 #3
0
        public async void AddAsync_Throw_Exception_If_Regulation_Does_Not_Exist()
        {
            // arrange
            const string regulationId = "ID";

            var rule = new WelcomeRegulationRule
            {
                RegulationId = regulationId
            };

            _regulationRepositoryMock.Setup(o => o.GetAsync(It.IsAny <string>()))
            .Returns(Task.FromResult <IRegulation>(null));

            // act
            Task task = _service.AddAsync(rule);

            // assert
            ServiceException exception = await Assert.ThrowsAsync <ServiceException>(async() => await task);

            Assert.Equal("Regulation not found.", exception.Message);
        }