Exemplo n.º 1
0
        /// <summary>
        /// Fill the database with these entries. We could do this by directly access the table and rows.
        /// But it is better to just add it via SQL.
        /// </summary>
        /// <param name="entries">The rows to insert into the database</param>
        /// <returns></returns>
        public WebTestBuilder WithTodoEntries(Todo[] entries)
        {
            var connection = new MemoryDbConnectionFactory(  ).Create(  );

            connection.Execute(_SqlInsertTable, entries);
            return(this);
        }
Exemplo n.º 2
0
        public async Task Edit_PostInvalidVersionString_PostFails()
        {
            var todoArray = new Todo[]
            {
                new Todo {
                    Description = "Task 1", CreatedDate = DateTime.Now
                }
            };
            var webTest  = new WebTestBuilder(  ).WithTodoEntries(todoArray).Build(  );
            var response = await webTest.Client.GetAsync(@"/Todos/Edit/1");

            var document = await HtmlHelpers.GetDocumentAsync(response);

            var values = new[]
            {
                new KeyValuePair <string, string>("ID", "1"),
                new KeyValuePair <string, string>("VersionString", Convert.ToBase64String(new byte [] { 0x1, 0x2, 0x3, 0x4 })),
                new KeyValuePair <string, string>("Description", "Updated Task 1"),
                new KeyValuePair <string, string>("CreatedDate", HtmlHelpers.GetInputValue(document, "formEdit", "CreatedDate")),
                new KeyValuePair <string, string>("__RequestVerificationToken", HtmlHelpers.GetInputValue(document, "formEdit", "__RequestVerificationToken"))
            };

            var formDataContent = new FormUrlEncodedContent(values);
            var url             = HtmlHelpers.GetFormUrl(document, "formEdit");
            var responsePost    = await webTest.Client.PostAsync(url, formDataContent);

            responsePost.StatusCode.Should(  ).Be(StatusCodes.Status404NotFound);

            var connection = new MemoryDbConnectionFactory(  ).Create(  );
            var todo       = await connection.QuerySingleAsync <Todo>("SELECT ID, Description, CreatedDate, Version FROM Todo WHERE ID=@id", new { id = 1 });

            todo.Description.Should( ).Be("Task 1");
        }