Exemplo n.º 1
0
        public void ShouldUpdateMilestoneWithNewInformation()
        {
            int expectedMilestoneId = 2;

            Model.Milestone updatedMilestone     = new Model.Milestone(2, 250d, null, null);
            string          expectedSqlStatement = "UPDATE saver.milestones SET target = @Target, DateMet = @DateMet, Description = @Description WHERE Id = @Id";

            mockDataAccess.Setup
            (
                da => da.ExecuteQueryWithGenericParameterType <Model.Milestone>
                (
                    It.Is <string>(val => val.Equals(expectedSqlStatement)),
                    It.IsAny <Model.Milestone>()
                )
            ).Returns(new Model.Milestone[] { updatedMilestone });
            mockSqlStringService.Setup(ss => ss.GetSqlFromResource(It.IsAny <string>())).Returns(expectedSqlStatement);


            IMilestoneRepository repository = new MilestoneRepository(mockDataAccess.Object, mockSqlStringService.Object);

            //Act
            Model.Milestone milestone = repository.Update(expectedMilestoneId, updatedMilestone);

            //Assert
            milestone.Should().NotBeNull();
            milestone.Id.Should().Be(expectedMilestoneId);
            milestone.Should().BeEquivalentTo(updatedMilestone);
        }
Exemplo n.º 2
0
        public async Task Update_DescriptionIsSet_AddsDescriptionParameter()
        {
            const string expected = "description";

            await _sut.Update(0, 0, description : expected);

            _request.Received().AddParameterIfNotNull("description", expected);
        }
Exemplo n.º 3
0
 public HttpResponseMessage Put(MilestoneDto dto)
 {
     try
     {
         if (dto != null)
         {
             MilestoneRepository.Update(dto);
             return(Request.CreateResponse(HttpStatusCode.OK));
         }
         return(Request.CreateResponse(HttpStatusCode.BadRequest));
     }
     catch (ElementNotFoundException e)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, e.Message));
     }
     catch (Exception)
     {
         return(Request.CreateResponse(HttpStatusCode.BadRequest, "Generic error happened."));
     }
 }