コード例 #1
0
        public async Task ThrowsIfcontextIsNull()
        {
            await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.CreateAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.DeleteAsync(null));

            await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.UpdateAsync(null));
        }
コード例 #2
0
        public async Task CreateAsyncHappyPath()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context = new CommandContext(CommandTypes.Create, request, model);

            model.StoreEntityAsync(Arg.Any <ConfigEntity>()).Returns(true);
            var result = await AllCommands.CreateAsync(context);

            Assert.True(result.IsSuccess);
            Assert.Equal("name", result.Result.Name);
            Assert.Equal("value", result.Result.Value);
        }
コード例 #3
0
        public async Task CreateAsyncStorageFailsReturnsStorageFailedOperationResult()
        {
            var request = new ConfigChangeRequest {
                Name = "name", Value = "value"
            };
            var context = new CommandContext(CommandTypes.Create, request, model);

            model.StoreEntityAsync(Arg.Any <ConfigEntity>()).Returns(false);
            var result = await AllCommands.CreateAsync(context);

            Assert.False(result.IsSuccess);
            Assert.Null(result.Result);
            Assert.Equal(ResultType.Forbidden, result.ResultType);
        }
コード例 #4
0
        public async Task ThrowsOnWrongArgumentType(CommandTypes expected, CommandTypes incoming)
        {
            var context = new CommandContext(incoming, new ConfigChangeRequest()
            {
                Name = "name", Value = "value"
            }, model);

            if (expected == CommandTypes.Create)
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.CreateAsync(context));
            }
            else if (expected == CommandTypes.Delete)
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.DeleteAsync(context));
            }
            else if (expected == CommandTypes.UpdateValue)
            {
                await Assert.ThrowsAsync <ArgumentException>(async() => await AllCommands.UpdateAsync(context));
            }
            else
            {
                throw new InvalidOperationException();
            }
        }