Exemplo n.º 1
0
        private static SqlCommand CreateInsertCommand(WarRequest request, SqlConnection connection)
        {
            var command = connection.CreateCommand();

            command.CommandText = "INSERT INTO [dbo].[Wars] (Title) OUTPUT inserted.[Id] VALUES (@Title)";
            command.CommandType = CommandType.Text;
            command.Parameters.AddWithValue("@Title", request.Title);
            return(command);
        }
Exemplo n.º 2
0
        internal async Task <int> Create(WarRequest request)
        {
            using (var connection = await CreateOpenConnection())
                using (var command = CreateInsertCommand(request, connection))
                {
                    var id = (int)await command.ExecuteScalarAsync();

                    return(id);
                }
        }
Exemplo n.º 3
0
        public async Task WarRepository_CRD_Test()
        {
            var sqlServerConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["WarDb"].ConnectionString;
            var repository = new WarRepository(sqlServerConnectionString);

            var request = new WarRequest
            {
                Title = "test Title"
            };
            var id = await repository.Create(request);

            var retrieved = await repository.Get(id);

            retrieved.Should().NotBeNull();
            retrieved.Title.Should().Be(request.Title);

            await repository.Delete(id);

            retrieved = await repository.Get(id);

            retrieved.Should().BeNull();
        }