Ejemplo n.º 1
0
        public async Task Post_Create_Update_ChangeStatus_Delete_Product_Return_All_Ok()
        {
            using (TestServer sharethingsServer = new ShareThingsScenarioBase().CreateServer())
            {
                HttpClient productClient = shareThingsScenarioBase.CreateHttpClientLender(sharethingsServer);

                #region Create product
                HttpResponseMessage response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.CreateProduct);

                var antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                HttpRequestMessage postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Product.Post.CreateProduct, antiForgeryValues)
                                                 .Set("Name", "TestName")
                                                 .Set("Description", "TestDescriptionCreated")
                                                 .Set("Type", "TestType")
                                                 .Set("Subtype", "TestSubtype")
                                                 .Set("Start", DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd HH:mm:ss"))
                                                 .Set("End", DateTime.Now.AddDays(26).ToString("yyyy-MM-dd HH:mm:ss"))
                                                 .Build();

                response = await productClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Product.Get.GetProducts, response.Headers.Location.OriginalString);

                // Get Id product
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.GetProducts);

                string responseString = await response.Content.ReadAsStringAsync();

                string key       = "/Products/Edit/";
                int    index     = responseString.IndexOf(key);
                int    productId = Convert.ToInt32(responseString.Substring(index + key.Length, 1));
                #endregion

                #region Get detail productId
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.GetDetails(productId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.Contains("TestDescriptionCreated", responseString);
                Assert.DoesNotContain("TestDescriptionUpdated", responseString);
                #endregion

                #region Edit product
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Common.EditProduct(productId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Product.Common.EditProduct(productId), antiForgeryValues)
                              .Set("ProductId", productId.ToString())
                              .Set("Name", "TestName")
                              .Set("Description", "TestDescriptionUpdated")
                              .Set("Type", "TestType")
                              .Set("Subtype", "TestSubtype")
                              .Build();

                response = await productClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Product.Get.GetProducts, response.Headers.Location.OriginalString);

                // Get detail productId
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.GetDetails(productId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.DoesNotContain("TestDescriptionCreated", responseString);
                Assert.Contains("TestDescriptionUpdated", responseString);
                Assert.Contains("<a href=\"/Products/StatusShary/" + productId + "\">UnShary</a>", responseString);
                Assert.DoesNotContain("<a href=\"/Products/StatusShary/" + productId + "\">Shary</a>", responseString);
                #endregion

                #region Change status
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Common.ChangeStatus(productId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Product.Common.ChangeStatus(productId), antiForgeryValues)
                              .Build();

                response = await productClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Product.Get.GetProducts, response.Headers.Location.OriginalString);

                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.GetDetails(productId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.DoesNotContain("<a href=\"/Products/StatusShary/" + productId + "\">UnShary</a>", responseString);
                Assert.Contains("<a href=\"/Products/StatusShary/" + productId + "\">Shary</a>", responseString);
                #endregion

                #region Delete product
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Common.DeleteProduct(productId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Product.Common.DeleteProduct(productId), antiForgeryValues)
                              .Build();

                response = await productClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Product.Get.GetProducts, response.Headers.Location.OriginalString);

                Func <Task> act = async() =>
                {
                    await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.GetDetails(productId));
                };
                act.Should().ThrowExactly <ArgumentException>().WithMessage("Product with Id 1 not exist (Parameter 'productId')");
                #endregion
            }
        }
        public async Task Get_Filter_By_Family_And_SubFamily_Return_All_Ok()
        {
            using (TestServer sharethingsServer = new ShareThingsScenarioBase().CreateServer())
            {
                HttpClient productClient = shareThingsScenarioBase.CreateHttpClientLender(sharethingsServer);
                HttpClient homeClient    = shareThingsScenarioBase.CreateHttpClientLender(sharethingsServer);

                string type    = "TestType";
                string subtype = "TestSubtype";
                int    productId;

                #region Create product
                HttpResponseMessage response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.CreateProduct);

                var antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                HttpRequestMessage postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Product.Post.CreateProduct, antiForgeryValues)
                                                 .Set("Name", "TestName")
                                                 .Set("Description", "TestDescriptionCreated")
                                                 .Set("Type", type)
                                                 .Set("Subtype", subtype)
                                                 .Set("Start", DateTime.Now.AddDays(-6).ToString("yyyy-MM-dd HH:mm:ss"))
                                                 .Set("End", DateTime.Now.AddDays(26).ToString("yyyy-MM-dd HH:mm:ss"))
                                                 .Build();

                response = await productClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Product.Get.GetProducts, response.Headers.Location.OriginalString);

                // Get Id product
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.GetProducts);

                string responseString = await response.Content.ReadAsStringAsync();

                string key   = "/Products/Edit/";
                int    index = responseString.IndexOf(key);
                productId = Convert.ToInt32(responseString.Substring(index + key.Length, 1));
                #endregion

                #region Home
                response = await homeClient.GetAsync(ShareThingsScenarioBase.Home.Get.GetHome);

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                key = string.Format("/Products/Details/{0}", productId);
                Assert.Contains(key, responseString);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Get, ShareThingsScenarioBase.Home.Get.GetHome, antiForgeryValues)
                              .Set("Family", type)
                              .Set("SubFamily", subtype)
                              .Build();

                response = await homeClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
                #endregion
            }
        }
Ejemplo n.º 3
0
        public async Task Post_Create_Update_ChangeDuration_AddComment_Reject_Confirm_Return_All_Ok()
        {
            using (TestServer sharethingsServer = new ShareThingsScenarioBase().CreateServer())
            {
                HttpClient productClient = shareThingsScenarioBase.CreateHttpClientLender(sharethingsServer);

                #region Create product
                HttpResponseMessage response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.CreateProduct);

                var antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                DateTime productStartDate = DateTime.Now.AddDays(-6);
                DateTime productEndDate   = DateTime.Now.AddDays(26);

                HttpRequestMessage postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Product.Post.CreateProduct, antiForgeryValues)
                                                 .Set("Name", "TestName")
                                                 .Set("Description", "TestDescriptionCreated")
                                                 .Set("Type", "TestType")
                                                 .Set("Subtype", "TestSubtype")
                                                 .Set("Start", productStartDate.ToString("yyyy-MM-dd HH:mm:ss"))
                                                 .Set("End", productEndDate.ToString("yyyy-MM-dd HH:mm:ss"))
                                                 .Build();

                response = await productClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Product.Get.GetProducts, response.Headers.Location.OriginalString);

                // Get Id product
                response = await productClient.GetAsync(ShareThingsScenarioBase.Product.Get.GetProducts);

                string responseString = await response.Content.ReadAsStringAsync();

                string key       = "/Products/Edit/";
                int    index     = responseString.IndexOf(key);
                int    productId = Convert.ToInt32(responseString.Substring(index + key.Length, 1));
                #endregion

                HttpClient borrowClient = shareThingsScenarioBase.CreateHttpClientBorrower(sharethingsServer);

                #region Create borrow 1
                response = await borrowClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.CreateBorrow(productId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                DateTime borrowDateStart = DateTime.Now.AddDays(-3);
                DateTime borrowDateEnd   = DateTime.Now.AddDays(23);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Borrow.Post.CreateBorrow, antiForgeryValues)
                              .Set("Borrow.ProductId", productId.ToString())
                              .Set("Borrow.ProductStart", productStartDate.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.ProductEnd", productEndDate.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.Start", borrowDateStart.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.End", borrowDateEnd.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Build();

                response = await borrowClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Borrow.Get.GetBorrows, response.Headers.Location.OriginalString);

                // Get borrow Id
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetBorrows);

                responseString = await response.Content.ReadAsStringAsync();

                key   = "/Borrows/Details/";
                index = responseString.IndexOf(key);
                int borrowId = Convert.ToInt32(responseString.Substring(index + key.Length, 1));
                #endregion

                #region Owner Product Details
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetOwnerDetails(borrowId));

                response.EnsureSuccessStatusCode();
                #endregion

                #region Change duration borrow
                DateTime borrowDateStartUpdated = DateTime.Now.AddDays(-2);
                DateTime borrowDateEndUpdated   = DateTime.Now.AddDays(20);

                response = await borrowClient.GetAsync(ShareThingsScenarioBase.Borrow.Common.EditBorrow(borrowId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Borrow.Common.EditBorrow(borrowId), antiForgeryValues)
                              .Set("id", borrowId.ToString())
                              .Set("Borrow.BorrowId", borrowId.ToString())
                              .Set("Borrow.ProductId", productId.ToString())
                              .Set("Borrow.ProductStart", productStartDate.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.ProductEnd", productEndDate.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.Start", borrowDateStartUpdated.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.End", borrowDateEndUpdated.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Build();

                response = await borrowClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Borrow.Get.GetBorrows, response.Headers.Location.OriginalString);

                // Get detail borrowId
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetDetails(borrowId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.DoesNotContain(borrowDateStart.ToString("yyyy-MM-dd"), responseString);
                Assert.DoesNotContain(borrowDateEnd.ToString("yyyy-MM-dd"), responseString);
                Assert.Contains(borrowDateStartUpdated.ToString("yyyy-MM-dd"), responseString);
                Assert.Contains(borrowDateEndUpdated.ToString("yyyy-MM-dd"), responseString);
                #endregion

                #region Add comment
                string comment = "New comment";

                response = await borrowClient.GetAsync(ShareThingsScenarioBase.Borrow.Common.AddComment(borrowId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Borrow.Common.AddComment(borrowId), antiForgeryValues)
                              .Set("id", borrowId.ToString())
                              .Set("Borrow.BorrowId", borrowId.ToString())
                              .Set("Comment.Text", comment)
                              .Build();

                response = await borrowClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.OK, response.StatusCode);

                // Get detail borrowId
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetDetails(borrowId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.Contains(comment, responseString);
                #endregion

                #region Set score
                int score = 5;

                response = await borrowClient.GetAsync(ShareThingsScenarioBase.Borrow.Common.Score(borrowId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Borrow.Common.Score(borrowId), antiForgeryValues)
                              .Set("id", borrowId.ToString())
                              .Set("Borrow.BorrowId", borrowId.ToString())
                              .Set("Borrow.Score", score.ToString())
                              .Build();

                response = await borrowClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);

                // Get detail borrowId
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetDetails(borrowId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.Contains("name=\"Borrow.Score\" value=\"" + score + "\"", responseString);
                #endregion

                #region Reject
                response = await borrowClient.GetAsync(ShareThingsScenarioBase.Borrow.Common.Reject(borrowId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Borrow.Common.Reject(borrowId), antiForgeryValues)
                              .Set("id", borrowId.ToString())
                              .Set("Borrow.BorrowId", borrowId.ToString())
                              .Build();

                response = await borrowClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);

                // Get detail borrowId
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetDetails(borrowId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.Contains("Rejected", responseString);
                #endregion

                #region Create borrow 2
                response = await borrowClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.CreateBorrow(productId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Borrow.Post.CreateBorrow, antiForgeryValues)
                              .Set("Borrow.ProductId", productId.ToString())
                              .Set("Borrow.ProductStart", productStartDate.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.ProductEnd", productEndDate.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.Start", borrowDateStart.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Set("Borrow.End", borrowDateEnd.ToString("yyyy-MM-dd HH:mm:ss"))
                              .Build();

                response = await borrowClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);
                Assert.EndsWith(ShareThingsScenarioBase.Borrow.Get.GetBorrows, response.Headers.Location.OriginalString);

                // Get borrow Id
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetBorrows);

                responseString = await response.Content.ReadAsStringAsync();

                key      = "/Borrows/Details/";
                index    = responseString.LastIndexOf(key);
                borrowId = Convert.ToInt32(responseString.Substring(index + key.Length, 1));
                #endregion

                #region Confirm
                response = await borrowClient.GetAsync(ShareThingsScenarioBase.Borrow.Common.Confirm(borrowId));

                antiForgeryValues = await AntiForgeryTokenExtractor.ExtractAntiForgeryValues(response);

                postRequest = new HttpRequestMessageBuilder(
                    HttpMethod.Post, ShareThingsScenarioBase.Borrow.Common.Confirm(borrowId), antiForgeryValues)
                              .Set("id", borrowId.ToString())
                              .Set("Borrow.BorrowId", borrowId.ToString())
                              .Build();

                response = await borrowClient.SendAsync(postRequest);

                Assert.Equal(HttpStatusCode.Found, response.StatusCode);

                // Get detail borrowId
                response = await productClient.GetAsync(ShareThingsScenarioBase.Borrow.Get.GetDetails(borrowId));

                response.EnsureSuccessStatusCode();
                responseString = await response.Content.ReadAsStringAsync();

                Assert.Contains("Accepted", responseString);
                #endregion
            }
        }