diff --git a/MyShop/MyShop.Core/Contracts/IBasketService.cs b/MyShop/MyShop.Core/Contracts/IBasketService.cs index 21a7a40..bd3b7ea 100644 --- a/MyShop/MyShop.Core/Contracts/IBasketService.cs +++ b/MyShop/MyShop.Core/Contracts/IBasketService.cs @@ -14,6 +14,7 @@ public interface IBasketService void RemoveFromBasket(HttpContextBase httpContext, string itemId); List GetBasketItems(HttpContextBase httpContext); BasketSummaryViewModel GetBasketSummary(HttpContextBase httpContext); + void ClearBasket(HttpContextBase httpContext); } } diff --git a/MyShop/MyShop.Core/Contracts/IOrderService.cs b/MyShop/MyShop.Core/Contracts/IOrderService.cs new file mode 100644 index 0000000..d98847a --- /dev/null +++ b/MyShop/MyShop.Core/Contracts/IOrderService.cs @@ -0,0 +1,18 @@ +using MyShop.Core.Models; +using MyShop.Core.ViewModels; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyShop.Core.Contracts +{ + public interface IOrderService + { + void CreateOrder(Order baseOrder, List basketItems); + List GetOrderList(); + Order GetOrder(string Id); + void UpdateOrder(Order updatedOrder); + } +} diff --git a/MyShop/MyShop.Core/Models/Order.cs b/MyShop/MyShop.Core/Models/Order.cs new file mode 100644 index 0000000..3e6fb3d --- /dev/null +++ b/MyShop/MyShop.Core/Models/Order.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyShop.Core.Models +{ + public class Order : BaseEntity + { + public Order() { + this.OrderItems = new List(); + } + + public string FirstName { get; set; } + public string Surname { get; set; } + public string Email { get; set; } + public string Street { get; set; } + public string City { get; set; } + public string State { get; set; } + public string ZipCode { get; set; } + public string OrderStatus { get; set; } + public virtual ICollection OrderItems { get; set; } + } +} diff --git a/MyShop/MyShop.Core/Models/OrderItem.cs b/MyShop/MyShop.Core/Models/OrderItem.cs new file mode 100644 index 0000000..e0ae2a4 --- /dev/null +++ b/MyShop/MyShop.Core/Models/OrderItem.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyShop.Core.Models +{ + public class OrderItem : BaseEntity + { + public string OrderId { get; set; } + public string ProductId { get; set; } + public string ProductName { get; set; } + public decimal Price { get; set; } + public string Image { get; set; } + public int Quanity { get; set; } + } +} diff --git a/MyShop/MyShop.Core/MyShop.Core.csproj b/MyShop/MyShop.Core/MyShop.Core.csproj index d710ecc..26b77f3 100644 --- a/MyShop/MyShop.Core/MyShop.Core.csproj +++ b/MyShop/MyShop.Core/MyShop.Core.csproj @@ -43,11 +43,14 @@ + + + diff --git a/MyShop/MyShop.DataAccess.SQL/DataContext.cs b/MyShop/MyShop.DataAccess.SQL/DataContext.cs index b269b5b..70cc391 100644 --- a/MyShop/MyShop.DataAccess.SQL/DataContext.cs +++ b/MyShop/MyShop.DataAccess.SQL/DataContext.cs @@ -11,7 +11,8 @@ namespace MyShop.DataAccess.SQL public class DataContext : DbContext { public DataContext() - : base("DefaultConnection") { + : base("DefaultConnection") + { } @@ -20,5 +21,7 @@ public DataContext() public DbSet Baskets { get; set; } public DbSet BasketItems { get; set; } public DbSet Customers { get; set; } + //public DbSet Orders { get; set; } + //public DbSet OrderItems { get; set; } } -} +} \ No newline at end of file diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.cs deleted file mode 100644 index 2f5f3f2..0000000 --- a/MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.cs +++ /dev/null @@ -1,42 +0,0 @@ -namespace MyShop.DataAccess.SQL.Migrations -{ - using System; - using System.Data.Entity.Migrations; - - public partial class Initial : DbMigration - { - public override void Up() - { - CreateTable( - "dbo.ProductCategories", - c => new - { - Id = c.String(nullable: false, maxLength: 128), - Category = c.String(), - CreatedAt = c.DateTimeOffset(nullable: false, precision: 7), - }) - .PrimaryKey(t => t.Id); - - CreateTable( - "dbo.Products", - c => new - { - Id = c.String(nullable: false, maxLength: 128), - Name = c.String(maxLength: 20), - Description = c.String(), - Price = c.Decimal(nullable: false, precision: 18, scale: 2), - Category = c.String(), - Image = c.String(), - CreatedAt = c.DateTimeOffset(nullable: false, precision: 7), - }) - .PrimaryKey(t => t.Id); - - } - - public override void Down() - { - DropTable("dbo.Products"); - DropTable("dbo.ProductCategories"); - } - } -} diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.cs deleted file mode 100644 index c49304a..0000000 --- a/MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace MyShop.DataAccess.SQL.Migrations -{ - using System; - using System.Data.Entity.Migrations; - - public partial class AddBasket : DbMigration - { - public override void Up() - { - CreateTable( - "dbo.BasketItems", - c => new - { - Id = c.String(nullable: false, maxLength: 128), - BasketId = c.String(maxLength: 128), - ProductId = c.String(), - Quanity = c.Int(nullable: false), - CreatedAt = c.DateTimeOffset(nullable: false, precision: 7), - }) - .PrimaryKey(t => t.Id) - .ForeignKey("dbo.Baskets", t => t.BasketId) - .Index(t => t.BasketId); - - CreateTable( - "dbo.Baskets", - c => new - { - Id = c.String(nullable: false, maxLength: 128), - CreatedAt = c.DateTimeOffset(nullable: false, precision: 7), - }) - .PrimaryKey(t => t.Id); - - } - - public override void Down() - { - DropForeignKey("dbo.BasketItems", "BasketId", "dbo.Baskets"); - DropIndex("dbo.BasketItems", new[] { "BasketId" }); - DropTable("dbo.Baskets"); - DropTable("dbo.BasketItems"); - } - } -} diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.cs deleted file mode 100644 index b7a9e79..0000000 --- a/MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace MyShop.DataAccess.SQL.Migrations -{ - using System; - using System.Data.Entity.Migrations; - - public partial class AddCustomer : DbMigration - { - public override void Up() - { - CreateTable( - "dbo.Customers", - c => new - { - Id = c.String(nullable: false, maxLength: 128), - UserId = c.String(), - FirstName = c.String(), - LastName = c.String(), - Email = c.String(), - Street = c.String(), - City = c.String(), - State = c.String(), - ZipCode = c.String(), - CreatedAt = c.DateTimeOffset(nullable: false, precision: 7), - }) - .PrimaryKey(t => t.Id); - - } - - public override void Down() - { - DropTable("dbo.Customers"); - } - } -} diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.Designer.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.Designer.cs similarity index 93% rename from MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.Designer.cs rename to MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.Designer.cs index eafc335..bf91e8d 100644 --- a/MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.Designer.cs +++ b/MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.Designer.cs @@ -13,7 +13,7 @@ public sealed partial class AddBasket : IMigrationMetadata string IMigrationMetadata.Id { - get { return "201711091321341_AddBasket"; } + get { return "202409170922120_AddBasket"; } } string IMigrationMetadata.Source diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.cs new file mode 100644 index 0000000..6bd019b --- /dev/null +++ b/MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.cs @@ -0,0 +1,16 @@ +namespace MyShop.DataAccess.SQL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class AddBasket : DbMigration + { + public override void Up() + { + } + + public override void Down() + { + } + } +} diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.resx b/MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.resx similarity index 100% rename from MyShop/MyShop.DataAccess.SQL/Migrations/201711091321341_AddBasket.resx rename to MyShop/MyShop.DataAccess.SQL/Migrations/202409170922120_AddBasket.resx diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.Designer.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.Designer.cs similarity index 92% rename from MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.Designer.cs rename to MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.Designer.cs index 13e68e6..f50cb3e 100644 --- a/MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.Designer.cs +++ b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.Designer.cs @@ -13,7 +13,7 @@ public sealed partial class AddCustomer : IMigrationMetadata string IMigrationMetadata.Id { - get { return "201801032024566_AddCustomer"; } + get { return "202409191004213_AddCustomer"; } } string IMigrationMetadata.Source diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.cs new file mode 100644 index 0000000..4fb6bff --- /dev/null +++ b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.cs @@ -0,0 +1,16 @@ +namespace MyShop.DataAccess.SQL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class AddCustomer : DbMigration + { + public override void Up() + { + } + + public override void Down() + { + } + } +} diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.resx b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.resx similarity index 100% rename from MyShop/MyShop.DataAccess.SQL/Migrations/201801032024566_AddCustomer.resx rename to MyShop/MyShop.DataAccess.SQL/Migrations/202409191004213_AddCustomer.resx diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.Designer.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.Designer.cs similarity index 93% rename from MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.Designer.cs rename to MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.Designer.cs index 41c1d99..37f5aa2 100644 --- a/MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.Designer.cs +++ b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.Designer.cs @@ -13,7 +13,7 @@ public sealed partial class Initial : IMigrationMetadata string IMigrationMetadata.Id { - get { return "201711071327340_Initial"; } + get { return "202409191228545_Initial"; } } string IMigrationMetadata.Source diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.cs b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.cs new file mode 100644 index 0000000..55da6cf --- /dev/null +++ b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.cs @@ -0,0 +1,16 @@ +namespace MyShop.DataAccess.SQL.Migrations +{ + using System; + using System.Data.Entity.Migrations; + + public partial class Initial : DbMigration + { + public override void Up() + { + } + + public override void Down() + { + } + } +} diff --git a/MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.resx b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.resx similarity index 70% rename from MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.resx rename to MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.resx index d610280..f458e03 100644 --- a/MyShop/MyShop.DataAccess.SQL/Migrations/201711071327340_Initial.resx +++ b/MyShop/MyShop.DataAccess.SQL/Migrations/202409191228545_Initial.resx @@ -118,7 +118,7 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - H4sIAAAAAAAEAO1ZzW7bRhC+F+g7EDy1gKOVlEMTg0rgSnZh1LKc0Ml9RY6kRZe77O7SkJ6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0ZEiUGvWfiBNd0awlhytO7EID60/XdAmstxhwBef8GeYiyYvro+HxqFJJ9fVUNRmcO27n0qa9p/fpE2L2I2Jqgn/D4qECWEmNTamDFxP9r3jmiTb9Pct2OEfaDQP9nmhD7e82jtYqMso4+sFDix/7olUKiQjtUDSyKsXtwGdUTuinKW7paeDnLRcVHa5dPYvU6i9SByW3ciHKRravFJtshFYtKNkIrFQ0shFSuTBkIyi5+GNDnqQCj42QKkUcmy3vOTyy9dZzUI5Zfbg9WF0csA7q4o9SbNBPEzWVBRtptlQ94Oy6emAjVksVAl+9OW+hJmBbBQDJe+7+X/z397zf8Mz1Vb7nq8+HDTmimv9IaX2wT+63YMwPPmg7Mdi2B9x6Qi0P+s0EVoMXL/otj/11BKQygV61AMsulQB1BGtKCroRbqsXaCGk4u+3mqDmwb9D5YBsj9Un451UCqh5H/BM6f/kIDJwMi8gov+ao9gu+WQ+ZkpnfhYcKhxlQypbxhUWyIlSrUyQGbIFdEc517hK7RNyw/iS8ICdKb0JRRAKWDL2HtxSyi8KMW3043KIMs/jm3ir59tYArBJoo3uhr4PievkfF/UbGoNEFHs+hVDe6JLCIXgJMsc6dqnHYFS8eUh9x57gQtg/IZa6AmvwxvcRC/xHNnLLH3XDLJaEWWxj88ImjPk8RSjmA+fYMOOt3j7P0sUqHcuOgAA dbo diff --git a/MyShop/MyShop.DataAccess.SQL/MyShop.DataAccess.SQL.csproj b/MyShop/MyShop.DataAccess.SQL/MyShop.DataAccess.SQL.csproj index 56b077e..feb4a3f 100644 --- a/MyShop/MyShop.DataAccess.SQL/MyShop.DataAccess.SQL.csproj +++ b/MyShop/MyShop.DataAccess.SQL/MyShop.DataAccess.SQL.csproj @@ -48,17 +48,17 @@ - - - 201711071327340_Initial.cs + + + 202409170922120_AddBasket.cs - - - 201711091321341_AddBasket.cs + + + 202409191004213_AddCustomer.cs - - - 201801032024566_AddCustomer.cs + + + 202409191228545_Initial.cs @@ -75,14 +75,14 @@ - - 201711071327340_Initial.cs + + 202409170922120_AddBasket.cs - - 201711091321341_AddBasket.cs + + 202409191004213_AddCustomer.cs - - 201801032024566_AddCustomer.cs + + 202409191228545_Initial.cs diff --git a/MyShop/MyShop.Services/BasketService.cs b/MyShop/MyShop.Services/BasketService.cs index 64c7651..6c8bb60 100644 --- a/MyShop/MyShop.Services/BasketService.cs +++ b/MyShop/MyShop.Services/BasketService.cs @@ -143,5 +143,11 @@ join p in productContext.Collection() on item.ProductId equals p.Id return model; } } + + public void ClearBasket(HttpContextBase httpContext) { + Basket basket = GetBasket(httpContext, false); + basket.BasketItems.Clear(); + basketContext.Commit(); + } } } diff --git a/MyShop/MyShop.Services/MyShop.Services.csproj b/MyShop/MyShop.Services/MyShop.Services.csproj index 3948ccc..9708073 100644 --- a/MyShop/MyShop.Services/MyShop.Services.csproj +++ b/MyShop/MyShop.Services/MyShop.Services.csproj @@ -42,6 +42,7 @@ + diff --git a/MyShop/MyShop.Services/OrderService.cs b/MyShop/MyShop.Services/OrderService.cs new file mode 100644 index 0000000..6b43726 --- /dev/null +++ b/MyShop/MyShop.Services/OrderService.cs @@ -0,0 +1,49 @@ +using MyShop.Core.Contracts; +using MyShop.Core.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using MyShop.Core.ViewModels; + +namespace MyShop.Services +{ + public class OrderService : IOrderService + { + IRepository orderContext; + public OrderService(IRepository OrderContext) { + this.orderContext = OrderContext; + } + + public void CreateOrder(Order baseOrder, List basketItems) + { + foreach (var item in basketItems) { + baseOrder.OrderItems.Add(new OrderItem() + { + ProductId = item.Id, + Image = item.Image, + Price = item.Price, + ProductName = item.ProductName, + Quanity = item.Quanity + }); + } + + orderContext.Insert(baseOrder); + orderContext.Commit(); + } + + public List GetOrderList() { + return orderContext.Collection().ToList(); + } + + public Order GetOrder(string Id) { + return orderContext.Find(Id); + } + + public void UpdateOrder(Order updatedOrder) { + orderContext.Update(updatedOrder); + orderContext.Commit(); + } + } +} diff --git a/MyShop/MyShop.WebUI.Tests/Controllers/BasketControllerTests.cs b/MyShop/MyShop.WebUI.Tests/Controllers/BasketControllerTests.cs index 435b879..91016c7 100644 --- a/MyShop/MyShop.WebUI.Tests/Controllers/BasketControllerTests.cs +++ b/MyShop/MyShop.WebUI.Tests/Controllers/BasketControllerTests.cs @@ -8,6 +8,7 @@ using MyShop.WebUI.Controllers; using System.Web.Mvc; using MyShop.Core.ViewModels; +using System.Security.Principal; namespace MyShop.WebUI.Tests.Controllers { @@ -20,12 +21,15 @@ public void CanAddBasketItem() //setup IRepository baskets = new MockContext(); IRepository products = new MockContext(); + IRepository orders = new MockContext(); + IRepository customers = new MockContext(); var httpContext = new MockHttpContext(); IBasketService basketService = new BasketService(products, baskets); - var controller = new BasketController(basketService); + IOrderService orderService = new OrderService(orders); + var controller = new BasketController(basketService, orderService, customers); controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); //Act @@ -45,6 +49,8 @@ public void CanAddBasketItem() public void CanGetSummaryViewModel() { IRepository baskets = new MockContext(); IRepository products = new MockContext(); + IRepository orders = new MockContext(); + IRepository customers = new MockContext(); products.Insert(new Product() { Id = "1", Price = 10.00m }); products.Insert(new Product() { Id = "2", Price = 5.00m }); @@ -55,9 +61,9 @@ public void CanGetSummaryViewModel() { baskets.Insert(basket); IBasketService basketService = new BasketService(products, baskets); + IOrderService orderService = new OrderService(orders); + var controller = new BasketController(basketService, orderService, customers); - - var controller = new BasketController(basketService); var httpContext = new MockHttpContext(); httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") { Value = basket.Id }); controller.ControllerContext = new System.Web.Mvc.ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); @@ -71,5 +77,52 @@ public void CanGetSummaryViewModel() { } + + [TestMethod] + public void CanCheckoutAndCreateOrder() { + IRepository customers = new MockContext(); + IRepository products = new MockContext(); + products.Insert(new Product() { Id = "1", Price = 10.00m }); + products.Insert(new Product() { Id = "2", Price = 5.00m }); + + IRepository baskets = new MockContext(); + Basket basket = new Basket(); + basket.BasketItems.Add(new BasketItem() { ProductId = "1", Quanity = 2, BasketId = basket.Id }); + basket.BasketItems.Add(new BasketItem() { ProductId = "1", Quanity = 1, BasketId = basket.Id }); + + baskets.Insert(basket); + + IBasketService basketService = new BasketService(products, baskets); + + IRepository orders = new MockContext(); + IOrderService orderService = new OrderService(orders); + + customers.Insert(new Customer() { Id = "1", Email = "brett.hargreaves@gmail.com", ZipCode = "90210" }); + + IPrincipal FakeUser = new GenericPrincipal(new GenericIdentity("brett.hargreaves@gmail.com", "Forms"), null); + + + var controller = new BasketController(basketService, orderService, customers); + var httpContext = new MockHttpContext(); + httpContext.User = FakeUser; + httpContext.Request.Cookies.Add(new System.Web.HttpCookie("eCommerceBasket") + { + Value = basket.Id + }); + + controller.ControllerContext = new ControllerContext(httpContext, new System.Web.Routing.RouteData(), controller); + + //Act + Order order = new Order(); + controller.Checkout(order); + + //assert + Assert.AreEqual(2, order.OrderItems.Count); + Assert.AreEqual(0, basket.BasketItems.Count); + + Order orderInRep = orders.Find(order.Id); + Assert.AreEqual(2, orderInRep.OrderItems.Count); + + } } } diff --git a/MyShop/MyShop.WebUI.Tests/Mocks/MockHttpContext.cs b/MyShop/MyShop.WebUI.Tests/Mocks/MockHttpContext.cs index 6c0d3c2..694b847 100644 --- a/MyShop/MyShop.WebUI.Tests/Mocks/MockHttpContext.cs +++ b/MyShop/MyShop.WebUI.Tests/Mocks/MockHttpContext.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Principal; using System.Text; using System.Threading.Tasks; using System.Web; @@ -12,6 +13,7 @@ public class MockHttpContext : HttpContextBase private MockRequest request; private MockResponse response; private HttpCookieCollection cookies; + private IPrincipal FakeUser; public MockHttpContext() { cookies = new HttpCookieCollection(); @@ -19,6 +21,16 @@ public MockHttpContext() { this.response = new MockResponse(cookies); } + public override IPrincipal User { + get { + return this.FakeUser; + } + set { + this.FakeUser = value; + } + + } + public override HttpRequestBase Request { get { return request; diff --git a/MyShop/MyShop.WebUI.Tests/MyShop.WebUI.Tests.csproj b/MyShop/MyShop.WebUI.Tests/MyShop.WebUI.Tests.csproj index 8b6d9b6..6e1317e 100644 --- a/MyShop/MyShop.WebUI.Tests/MyShop.WebUI.Tests.csproj +++ b/MyShop/MyShop.WebUI.Tests/MyShop.WebUI.Tests.csproj @@ -1,4 +1,5 @@  + Debug @@ -25,6 +26,7 @@ DEBUG;TRACE prompt 4 + Off pdbonly @@ -122,6 +124,7 @@ +