public void Delete_Category_Should_Delete_Category_In_Database() { var category = new Category(); _sut.CreateCategory(category); A.CallTo(() => _repository.Persist(A<Category>._)).Returns(category); A.CallTo(() => _repository.GetById(A<int>._)).Returns(category); var result = _repository.GetById(1); Assert.That(result, Is.EqualTo(category)); _sut.DeleteCategory(1); A.CallTo(() => _repository.Delete(A<Category>._)).MustHaveHappened(); A.CallTo(() => _repository.GetById(1)).Returns(null); //var result = _repository.GetById(1); var result2 = _repository.GetById(1); //A.CallTo(() => _repository.GetById(1)).Equals(null); Assert.That(result2, Is.EqualTo(null)); Assert.That(result, Is.EqualTo(category)); }
public void CreateCategory_Should_Persist_Category_In_Database() { var category = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); var result = _sut.CreateCategory(category); A.CallTo(() => _repository.Persist(category)).MustHaveHappened(); //Assert.That(result.Id.Value, Is.EqualTo(category.Id.Value)); }
public void GetAllCategories_Should_Return_IEnumerable_Of_Categories() { var category = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); var result = _sut.CreateCategory(category); var res = _sut.GetAllCategories(); A.CallTo(() => _repository.Persist(category)).MustHaveHappened(); A.CallTo(() => _repository.GetAll()).MustHaveHappened(); A.CallTo(() => _repository.GetAll()).Equals(res); }
public void GetCategoryByName_Should_GetAll_Category_In_DataBase() { var expected = new Category(); A.CallTo(() => _repository.Persist(A<Category>._)).Returns(expected); _sut.CreateCategory(expected); var result = _sut.GetCategoryByName("Sakura"); A.CallTo(() => _repository.GetAll()).MustHaveHappened(); }
public void Update_Should_Throw_Expection_When_There_Is_No_Category_With_Given_Id() { var category1 = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); var category2 = new Category("AGD", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); category1.Name = "RTV & AGD"; var result =_sut.UpdateCategory(11, category1); A.CallTo(() => _repository.Persist(category1)).Throws<CategoryDoesNotExist>(); }
public Category UpdateCategory(int category_id, Category updated_category) { var category = _repository.GetById(category_id); if (category == null) throw new CategoryDoesNotExist(); else { updated_category.Id = category_id; return _repository.Persist(updated_category); } }
public void UpdateCategory_Should_Change_Name_Of_Given_Category() { var category = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); var original_category = _sut.CreateCategory(category); A.CallTo(() => _repository.Persist(category)).MustHaveHappened(); A.CallTo(() => _repository.GetById(1)).Returns(original_category); var edited_category = _sut.UpdateCategory(1, category); A.CallTo(() => _repository.GetById(1)).Returns(edited_category); }
public void GetProductById_Should_Return_Product() { var category = new Category(); var product = new Product("Overlord", "o nekromancie", 1, 2, 3, 4, 5, category); var create = _sut.CreateProduct(product); A.CallTo(() => _repository.Persist(A<Product>._)).Returns(product); A.CallTo(() => _repository.GetById(A<int>._)).Returns(product); var result = _sut.GetProductById(2); Assert.That(result, Is.EqualTo(product)); }
public void GetCategoryById_Should_Return_Category() { var category = new Category("AGD", "styl", "wykonanie", "użyteczność", "cena/jakość", "popularność"); _sut.CreateCategory(category); A.CallTo(() => _repository.Persist(A<Category>._)).Returns(category); A.CallTo(() => _repository.GetById(A<int>._)).Returns(category); //var create = _sut.CreateCategory(category); var result = _sut.GetCategoryById(12); Trace.Write(result); Trace.Write(category); Assert.That(result, Is.EqualTo(category)); }
public static void Main(string[] args) { /* Sprawdzałem, czy jestem w stanie użyć stworzonego kontekstu i ręcznie dodać jakikolwiek rekord do bazy danych. Działa bez zarzutów. */ using (var db = new JudgifyContext()) { Console.WriteLine("Category is being created..."); var cat = new Category { Name = "RTV", AddDate = DateTime.Now, Criterion1 = "moc", Criterion2 = "wykonanie", Criterion3 = "użyteczność", Criterion4 = "cena/jakość", Criterion5 = "popularność", Products = null }; db.Categories.Add(cat); Console.WriteLine("Category added to database..."); db.SaveChanges(); Console.WriteLine("Changes saved..."); var query = from c in db.Categories select c; //if (query == null) //{ // Console.WriteLine("Database is empty."); //} //else //{ Console.WriteLine("All categories in the database:"); foreach (var item in query) { Console.WriteLine(item.Name); } // } // Console.WriteLine("Press any key to exit..."); // Console.ReadKey(); } }
public void UpdateCategory_Should_Return_Null_When_There_Is_No_Category_With_Given_Id() { var category1 = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); var category2 = new Category("AGD", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); var existing_category = _sut.CreateCategory(category1); A.CallTo(() => _repository.Persist(category1)).Returns(existing_category); var result = _sut.UpdateCategory(152, category2); A.CallTo(() => _repository.GetById(152)).MustHaveHappened(); A.CallTo(() => _repository.GetById(152)).Returns(null); }
public void CreateCategory_Should_Return_Category_After_Persisting_It_In_Database() { var expected = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); var actual = _sut.CreateCategory(expected); // Nie rozumiem FakeItEasy, nie ruszam tego póki co. //A.CallTo(() => _repository.Persist(A<Category>._)).Returns(expected); // Tu również ciągnie się błąd z testów "repository", // Obiekty są takie same, ale NUnit twierdzi co innego. //Assert.That(actual, Is.EqualTo(expected)); Assert.That(actual.Name, Is.EqualTo(expected.Name)); Assert.That(actual.Id, Is.EqualTo(expected.Id)); }
public Product(string name, string description, float averageCriterion1, float averageCriterion2, float averageCriterion3, float averageCriterion4, float averageCriterion5, Category category) { //Opinions = new List<Opinion>(); Name = name; Description = description; AddDate = DateTime.Now; AverageCriterion1 = averageCriterion1; AverageCriterion2 = averageCriterion2; AverageCriterion3 = averageCriterion3; AverageCriterion4 = averageCriterion4; AverageCriterion5 = averageCriterion5; AverageDegree = (averageCriterion1 + averageCriterion2 + averageCriterion3 + averageCriterion4 + averageCriterion5) / 5; //Category = category; CategoryId = category.Id; }
public void Update_Should_Persist_And_Return_Category() { // var category = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); // var upd_cat = new Category("AGD", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność"); //var cat = _sut.CreateCategory(category); //var catr = new Category(); // var result = _sut.UpdateCategory(1, catr); //Trace.Write(result); //A.CallTo(() => _repository.Persist(catr)).MustHaveHappened(); // Assert.That(result, Is.EqualTo(new Category())); var expected = new Category(); A.CallTo(() => _repository.Persist(A<Category>._)) .Returns(expected); var result = _sut.UpdateCategory(1,new Category()); Assert.That(result, Is.EqualTo(expected)); }
public Product ChangeProductCategory(int product_id, Category category) { Product product = _repository.GetById(product_id); product.CategoryId = category.Id; return _repository.Persist(product); }
public IHttpActionResult UpdateCategory(int id, [FromBody] CategoryCreateModel param) { var category = new Category(param.Name, param.Criterion1, param.Criterion2, param.Criterion3, param.Criterion4, param.Criterion5); var updated_category = _categoryService.UpdateCategory(id, category); return CreatedAtRoute("GetCategoryByName", new { name = updated_category.Name }, updated_category); }
public Category CreateCategory(Category category) { category.AddDate = DateTime.Now; return _repository.Persist(category); }