예제 #1
0
        public void InsertCommand_Default_IsSuccessfulFalseAndDataIsNull()
        {
            var cmd = new CommandInsertRow(_tableNameFixture, _colsFixture);

            cmd.IsSuccessful.Should().BeFalse();
            cmd.Data.Should().BeNull();
        }
예제 #2
0
        public async Task ExecuteAsync_HappyPath_IsSuccessfulReturnTrue()
        {
            var dbCommand = CreateDbCommandForHappyPath();

            var command = new CommandInsertRow(_tableNameFixture, _colsFixture);

            await command.ExecuteAsync(dbCommand);

            command.IsSuccessful.Should().BeTrue();
        }
예제 #3
0
        public async Task ExecuteAsync_VerifyBehavior()
        {
            var dbCommand = CreateDbCommandForHappyPath();
            var command   = new CommandInsertRow(_tableNameFixture, _colsFixture);

            await command.ExecuteAsync(dbCommand);

            dbCommand.CountCallCommandText.Should().Be(1);
            dbCommand.CountCallDbParameterCollection.Should().Be(1);
            dbCommand.CountCallExecuteScalarAsync.Should().Be(1);
        }
예제 #4
0
        public async Task ExecuteAsync_HappyPath_CreateIdReturnGeneratedId()
        {
            var expectedId = new Fixture().Create <int>();
            var dbCommand  = CreateDbCommandForHappyPath(expectedId: expectedId);

            var command = new CommandInsertRow(_tableNameFixture, _colsFixture);

            await command.ExecuteAsync(dbCommand);

            command.CreatedId.Should().Be(expectedId);
        }
예제 #5
0
        public async Task ExecuteAsync_HappyPath_DataReturnGeneratedResponse()
        {
            var expectedResponse = new Fixture().Create <string>();
            var dbCommand        = CreateDbCommandForHappyPath(expectedResponse: expectedResponse);

            var command = new CommandInsertRow(_tableNameFixture, _colsFixture);

            await command.ExecuteAsync(dbCommand);

            command.Data.Should().Be(expectedResponse);
        }
예제 #6
0
        public async Task <ActionResult> Create(string name, [FromBody] JsonElement json)
        {
            var command = new CommandInsertRow(name, json.ToString());
            await _dbCon.ExecuteAsync(command);

            if (!command.IsSuccessful)
            {
                return(BadRequest(command.Error));
            }

            Response.StatusCode = StatusCodes.Status201Created;
            Response.Headers.Add("Location", $"api/Table/{name}/Row/{command.CreatedId}");
            return(Content(command.Data, "application/json"));
        }