PageRenderTime 35ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/MusicStore.UnitTest/DeleteCommandHandlerUnitTest.cs

https://github.com/satish860/MusicStoreAPI
C# | 57 lines | 52 code | 5 blank | 0 comment | 0 complexity | 6e9562c4c799b7cba40c311b8dfe9841 MD5 | raw file
  1. using MusicStore.Api.CommandHandlers;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using MusicStore.Api;
  8. using Simple.Data;
  9. using FluentAssertions;
  10. using NUnit.Framework;
  11. using System.Web.Http.SelfHost;
  12. using MusicStore.Api.Models;
  13. namespace MusicStore.UnitTest
  14. {
  15. [TestFixture]
  16. public class DeleteCommandHandlerUnitTest
  17. {
  18. [TestFixtureSetUp]
  19. public void SetUp()
  20. {
  21. new MusicStoreBootStrap(new HttpSelfHostConfiguration("http://localhost:8008"))
  22. .ConfigureDatabaseForTest()
  23. .SeedDatabase();
  24. }
  25. [SetUp]
  26. public void testSetUp()
  27. {
  28. var Db = Database.Open();
  29. Db.Cart.Insert(new Cart { Id = 1 });
  30. }
  31. [TearDown]
  32. public void TearDown()
  33. {
  34. var Db = Database.Open();
  35. Db.CartItem.DeleteByCartId(1);
  36. Db.Cart.DeleteById(1);
  37. }
  38. [Test]
  39. public void Should_be_able_to_Delete_the_Cart_Item_from_the_Cart()
  40. {
  41. ICommandHandler<AddProductToCartCommand> command = TestInstance.AddProductToCommandHandler;
  42. command.Execute(new AddProductToCartCommand { CartId = 1, ProductId = 1, Quantity = 1 });
  43. ICommandHandler<DeleteItemFromCartCommand> CommandHandler = TestInstance.DeleteCommandHandler;
  44. CommandHandler.Execute(new DeleteItemFromCartCommand { CartId = 1, ProductId = 1 });
  45. var Db = Database.Open();
  46. IEnumerable<CartItem> items = Db.CartItem.FindAllByCartId(1);
  47. Cart cart=Db.Cart.FindById(1);
  48. cart.Price.Should().Be(0);
  49. items.Count().Should().Be(0);
  50. }
  51. }
  52. }