Exemplo n.º 1
0
        public void ListAllCategoriesMock()
        {
            var repo         = new CategoryMock();
            var categoryList = repo.ListAllCategories();

            Assert.AreEqual(3, categoryList.Count);
        }
Exemplo n.º 2
0
        public override void Setup()
        {
            base.Setup();
            context.Categories.Add(CategoryMock.GetValidSingle());
            context.SaveChanges();
            var category = context.Categories.First();

            context.Books.AddRange(BookMock.GetList());
            context.SaveChanges();
            _bookRepository = unitOfWork.GetGenericRepository <Book>();
        }
Exemplo n.º 3
0
        public void ReturnAStringWithTheCategoryDetailsInTheCorrectFormat()
        {
            // Arrange
            var category = new CategoryMock("name");

            var expectedResult = string.Format("{0} category - {1} {2} in total", category.Name,
                                               category.Products.Count, category.Products.Count != 1 ? "products" : "product");

            // Act
            var message = category.Print();

            // Assert
            Assert.AreEqual(expectedResult.ToString(), message);
        }
Exemplo n.º 4
0
        public void When_AddNewBook_NotValidCategory_Then_ReturnException()
        {
            var categoryNull = CategoryMock.GetNull();

            _categoryRepo.GetById(0).Returns(categoryNull);
            try
            {
                _bookBLL.AddNewBook(BookMock.GetInputWithNotValidCategoryMock());
                Assert.Fail();
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(BLLException));
                Assert.AreEqual(ExceptionCodes.BLLExceptions.CategoryNotFound.ToString(), ((BLLException)ex).Code);
                throw ex;
            }
        }
Exemplo n.º 5
0
        public void When_AddNewBook_Success()
        {
            //arrange
            var newBook = new CreateNewBookInput
            {
                Title      = "Asp.Net Core",
                Price      = 20,
                CategoryId = 1
            };

            _categoryRepo.GetById(newBook.CategoryId).Returns(CategoryMock.GetValidSingle());
            try
            {
                //act
                _bookBLL.AddNewBook(newBook);
                _bookRepo.Received().Insert(Arg.Any <Book>());
            }
            catch
            {
                //assert
                Assert.Fail();
            }
        }
 public void ShouldUseCategory()
 {
     CategoryMock.Verify(x => x.GetAllAsync());
 }
 public void SetUp()
 {
     CategoryMock.Setup(x => x.GetAllAsync())
     .Returns(Task.FromResult(CategorySamples.All));
     Assert.DoesNotThrow(() => _result = UnderTest.GetAll());
 }