public void Delete_Should_Delete_Opinion_In_Database()
        {
            var opinion = new Opinion("Swietny sprzet", 2, 3, 1, 5, 3, 1, 1);

            _sut.CreateOpinion(opinion);

            A.CallTo(() => _opinionRepository.Persist(A<Opinion>._)).Returns(opinion);
            A.CallTo(() => _opinionRepository.GetById(A<int>._)).Returns(opinion);

            var result = _opinionRepository.GetById(1);

            Assert.That(result, Is.EqualTo(opinion));

            _sut.DeleteOpinion(1);

            A.CallTo(() => _opinionRepository.Delete(A<Opinion>._)).MustHaveHappened();

            A.CallTo(() => _opinionRepository.GetById(1)).Returns(null);

            //var result = _repository.GetById(1);
            var result2 = _opinionRepository.GetById(1);

            //A.CallTo(() => _repository.GetById(1)).Equals(null);

            Assert.That(result2, Is.EqualTo(null));
            Assert.That(result, Is.EqualTo(opinion));
        }
        public void CreateOpinion_Should_Persist_Opinion_In_Database()
        {
            var opinion = new Opinion("Swietny sprzet", 2, 3, 1, 5, 3, 1, 1);

            var result = _sut.CreateOpinion(opinion);

            A.CallTo(() => _opinionRepository.Persist(opinion)).MustHaveHappened();
        }
        public void ChangeOpinion_Should_Return_Opinion()
        {
            var expected = new Opinion();
            A.CallTo(() => _opinionRepository.Persist(A<Opinion>._))
                .Returns(expected);

            var result = _sut.UpdateOpinion(1, new Opinion());

            Assert.That(result, Is.EqualTo(expected));
        }
        public void CreateOpinion_Should_Persist_Opinion_In_Database()
        {
            //var category = new Category("RTV", "moc", "wykonanie", "użyteczność", "cena/jakość", "popularność");
            var opinion = new Opinion("naprawde super sprzet,", 3, 2, 4, 4, 2);
            var result = _sut.CreateOpinion(opinion);
            //var result = _sut.CreateCategory(category);

            // Nie rozumiem FakeItEasy, nie ruszam tego póki co.
            //A.CallTo(() => _repository.Persist(category)).MustHaveHappened();
            Assert.That(result.Name, Is.EqualTo("RTV"));
            Assert.That(result.Id.Value, Is.EqualTo(category.Id.Value));
        }
        public void GetOpinionById_Should_Return_Opinion()
        {
            var opinion = new Opinion("bardzo fajny", 5, 6, 4, 3, 5, 1, 1);

            _sut.CreateOpinion(opinion);

            A.CallTo(() => _opinionRepository.Persist(A<Opinion>._)).Returns(opinion);
            A.CallTo(() => _opinionRepository.GetById(A<int>._)).Returns(opinion);
            //var create = _sut.CreateCategory(category);
            var result = _sut.GetOpinionById(12);
            Assert.That(result, Is.EqualTo(opinion));
        }
        public void ChangeOpinion_Should_Persist_Opinion_In_Repository()
        {
            var newOpinion = new Opinion("Beznadziejny", 1, 2, 2, 1, 2, 1, 1);
            var previousOpinion = new Opinion("to chyba najgorsza rzecz jaką miałem", 1, 2, 2, 1, 2, 1, 1);
            //var opinion2 = new Model.Opinion("Beznadziejny", 1, 2, 2, 1, 2);

            var result_previous_opinion = _sut.CreateOpinion(previousOpinion);

            A.CallTo(() => _opinionRepository.Persist(previousOpinion)).MustHaveHappened();

            var result_new_opinion = _sut.UpdateOpinion(1, newOpinion);

            A.CallTo(() => _opinionRepository.Persist(newOpinion)).MustHaveHappened();
            Assert.That(result_new_opinion, Is.Not.EqualTo(result_previous_opinion));
        }
        public IHttpActionResult UpdateOpinion(int id, [FromBody] OpinionCreateModel param)
        {
            var opinion = new Opinion(param.Comment, param.Criterion1, param.Criterion2,
                param.Criterion3, param.Criterion4, param.Criterion5, param.ProductId, param.UserID);
            var updated_opinion = _opinionService.UpdateOpinion(id, opinion);

            return CreatedAtRoute("GetOpinionById", new { id = updated_opinion.Id }, updated_opinion);
        }
 public Opinion UpdateOpinion(int id, Opinion opinion)
 {
     opinion.PreviousOpinionId = id;
     return _repository.Persist(opinion);
 }
 public Opinion CreateOpinion(Opinion opinion)
 {
     return _repository.Persist(opinion);
 }