Exemple #1
0
        public void AutoFillList_FillWith3Elements()
        {
            var element = AutoFill <TestList> .One();

            Assert.That(element.IntValues, Is.EquivalentTo(new[] { 1, 2, 3 }));
            Assert.That(element.StringValues, Is.EquivalentTo(new[] { "some-string-values0", "some-string-values1", "some-string-values2" }));
        }
Exemple #2
0
        public void AutoFillStringValue_WithRandomFlag_SuffixRandomValue()
        {
            var element = AutoFill <TestStringClass> .One(AutoFillFlags.RandomizeString);

            Assert.That(element.Name, Does.Match("^some-name-([a-f0-9]{16})$"));
            Assert.That(element.Description, Does.Match("^some-description-([a-f0-9]{16})$"));
            Assert.That(element.MultipleWordProperty, Does.Match("^some-multiple-word-property-([a-f0-9]{16})$"));
        }
Exemple #3
0
        public void AutoFillStringValue_PrefixVariableNameWithSome()
        {
            var element = AutoFill <TestStringClass> .One();

            Assert.That(element.Name, Does.Match("^some-name$"));
            Assert.That(element.Description, Does.Match("^some-description$"));
            Assert.That(element.MultipleWordProperty, Does.Match("^some-multiple-word-property$"));
        }
Exemple #4
0
        public void AutoFill_DoNotFilIgnoredFields()
        {
            var element = AutoFill <TestIgnoring> .One(ignoring : (i) => new { i.Ignored, i.Child.SubIgnored });

            Assert.That(element.Value, Is.EqualTo(1));
            Assert.That(element.Ignored, Is.Null);
            Assert.That(element.Child.SubIgnored, Is.Null);
        }
Exemple #5
0
        public void AutoFillRecursiveObject_StopWhenMaxDepthIsReached()
        {
            var element = AutoFill <TestRecursive> .One(settings : new AutoFillSettings {
                MaxDepth = 1
            });

            Assert.That(element.Recursive.Recursive, Is.Null);
        }
Exemple #6
0
        public void AutoFillObject_ContinueIncrementing()
        {
            var element = AutoFill <TestObjectType> .One();

            Assert.That(element.IntValue, Is.EqualTo(1));
            Assert.That(element.SubObject, Is.Not.Null);
            Assert.That(element.SubObject.SubIntValue, Is.EqualTo(2));
        }
Exemple #7
0
        public void EditEffect_WhenEffectDoesNotExists_Throw()
        {
            var executionContext  = new NaheulbookExecutionContext();
            var editEffectRequest = AutoFill <EditEffectRequest> .One();

            _effectRepository.GetWithModifiersAsync(Arg.Any <int>())
            .Returns((Effect)null);

            Func <Task> act = () => _effectService.EditEffectAsync(executionContext, 42, editEffectRequest);

            act.Should().Throw <EffectNotFoundException>();
        }
Exemple #8
0
        public async Task CreateEffectType_AddANewEffectTypeInDatabase()
        {
            var createEffectTypeRequest = AutoFill <CreateEffectTypeRequest> .One();

            var effectType = await _effectService.CreateEffectTypeAsync(new NaheulbookExecutionContext(), createEffectTypeRequest);

            Received.InOrder(() =>
            {
                _effectTypeRepository.Add(effectType);
                _unitOfWork.SaveChangesAsync();
            });
            effectType.Name.Should().Be("some-name");
        }
Exemple #9
0
        public async Task CreateEffect_EnsureThatUserIsAnAdmin_BeforeAddingInDatabase()
        {
            var executionContext    = new NaheulbookExecutionContext();
            var createEffectRequest = AutoFill <CreateEffectRequest> .One();

            await _effectService.CreateEffectAsync(executionContext, 2, createEffectRequest);

            Received.InOrder(() =>
            {
                _authorizationUtil.EnsureAdminAccessAsync(executionContext);
                _unitOfWork.SaveChangesAsync();
            });
        }
Exemple #10
0
        public void AutoFillIntegerValues_IncrementByOne()
        {
            var element = AutoFill <TestIntClass> .One();

            Assert.That(element.IntValue, Is.EqualTo(1));
            Assert.That(element.ShortValue, Is.EqualTo(2));
            Assert.That(element.CharValue, Is.EqualTo(3));
            Assert.That(element.LongValue, Is.EqualTo(4));
            Assert.That(element.ByteValue, Is.EqualTo(5));
            Assert.That(element.FloatValue, Is.EqualTo(6));
            Assert.That(element.DoubleValue, Is.EqualTo(7));
            Assert.That(element.DecimalValue, Is.EqualTo(8));
            Assert.That(element.BoolValue, Is.EqualTo(true));
        }
Exemple #11
0
        public async Task CreateEffect_AddANewEffectInDatabase()
        {
            var expectedEffect      = CreateEffect(subCategoryId: 2);
            var createEffectRequest = AutoFill <CreateEffectRequest> .One();

            var executionContext = new NaheulbookExecutionContext();

            var effect = await _effectService.CreateEffectAsync(executionContext, 2, createEffectRequest);

            Received.InOrder(() =>
            {
                _effectRepository.Add(effect);
                _unitOfWork.SaveChangesAsync();
            });
            effect.Should().BeEquivalentTo(expectedEffect);
        }
Exemple #12
0
        public async Task CreateEffectSubCategory_AddANewEffectSubCategoryInDatabase()
        {
            var expectedEffectSubCategory = CreateEffectSubCategory();

            expectedEffectSubCategory.Effects = new List <Effect>();
            var createEffectSubCategoryRequest = AutoFill <CreateEffectSubCategoryRequest> .One();

            var effectSubCategory = await _effectService.CreateEffectSubCategoryAsync(new NaheulbookExecutionContext(), createEffectSubCategoryRequest);

            Received.InOrder(() =>
            {
                _effectSubCategoryRepository.Add(effectSubCategory);
                _unitOfWork.SaveChangesAsync();
            });
            effectSubCategory.Should().BeEquivalentTo(expectedEffectSubCategory);
        }
        public async Task CreateItemTemplateSubCategory_AddANewItemTemplateSubCategoryInDatabase()
        {
            var expectedItemTemplateSubCategory      = CreateItemTemplateSubCategoryAsync();
            var createItemTemplateSubCategoryRequest = AutoFill <CreateItemTemplateSubCategoryRequest> .One(settings : new AutoFillSettings {
                MaxDepth = 0
            });

            var itemTemplateSubCategory = await _itemTemplateSubCategoryService.CreateItemTemplateSubCategoryAsync(new NaheulbookExecutionContext(), createItemTemplateSubCategoryRequest);

            Received.InOrder(() =>
            {
                _itemTemplateSubCategoryRepository.Add(itemTemplateSubCategory);
                _unitOfWork.SaveChangesAsync();
            });
            itemTemplateSubCategory.Should().BeEquivalentTo(expectedItemTemplateSubCategory);
        }
        public async Task CreateItemTemplateSection_AddANewItemTemplateSectionInDatabase()
        {
            var expectedItemTemplateSection      = CreateItemTemplateSection();
            var createItemTemplateSectionRequest = AutoFill <CreateItemTemplateSectionRequest> .One(settings : new AutoFillSettings {
                MaxDepth = 0
            });

            var itemTemplateSection = await _service.CreateItemTemplateSectionAsync(new NaheulbookExecutionContext(), createItemTemplateSectionRequest);

            var itemTemplateSectionRepository = _unitOfWorkFactory.GetUnitOfWork().ItemTemplateSections;

            Received.InOrder(() =>
            {
                itemTemplateSectionRepository.Add(itemTemplateSection);
                _unitOfWorkFactory.GetUnitOfWork().SaveChangesAsync();
            });
            itemTemplateSection.Should().BeEquivalentTo(expectedItemTemplateSection);
        }
Exemple #15
0
        public async Task EditEffect_EnsureThatUserIsAnAdmin_BeforeAddingInDatabase()
        {
            var executionContext = new NaheulbookExecutionContext();
            var previousEffect   = AutoFill <Effect> .One(AutoFillFlags.RandomizeString | AutoFillFlags.RandomInt);

            var editEffectRequest = AutoFill <EditEffectRequest> .One();

            previousEffect.Id = 42;

            _effectRepository.GetWithModifiersAsync(42)
            .Returns(previousEffect);

            await _effectService.EditEffectAsync(executionContext, 42, editEffectRequest);

            Received.InOrder(() =>
            {
                _authorizationUtil.EnsureAdminAccessAsync(executionContext);
                _unitOfWork.SaveChangesAsync();
            });
        }
Exemple #16
0
        public async Task EditEffect_UpdateEffectInDatabase()
        {
            var expectedEffect   = CreateEffect(42, subCategoryId: 1, offset: 1);
            var executionContext = new NaheulbookExecutionContext();
            var previousEffect   = AutoFill <Effect> .One(AutoFillFlags.RandomizeString | AutoFillFlags.RandomInt, new AutoFillSettings { MaxDepth = 1 }, (i) => new { Category = i.SubCategory });

            var editEffectRequest = AutoFill <EditEffectRequest> .One();

            previousEffect.Id = 42;

            _effectRepository.GetWithModifiersAsync(42)
            .Returns(previousEffect);

            await _effectService.EditEffectAsync(executionContext, 42, editEffectRequest);

            await _unitOfWork.Received(1)
            .SaveChangesAsync();

            previousEffect.Should().BeEquivalentTo(expectedEffect);
        }