コード例 #1
0
 public async Task<HttpResponseMessage> Update(UnitOfMeasureModel unitOfMeasure)
 {
     UnitOfMeasureModel model = new UnitOfMeasureModel();
     try
     {
         model = await _unitOfMeasureService.UpdateAsync(unitOfMeasure);
     }
     catch (HttpRequestException ex)
     {
         Trace.TraceError(ex.Message);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
     }
     catch (WebException we)
     {
         Trace.TraceError(we.Message);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, we.Message);
     }
     catch (SecurityException se)
     {
         Trace.TraceError(se.Message);
         return Request.CreateErrorResponse(HttpStatusCode.Forbidden, "Not Authorised to this server!!");
     }
     catch (Exception ex)
     {
         Trace.TraceError(ex.Message);
         return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message);
     }
     return Request.CreateResponse(HttpStatusCode.OK, model);
 }
        public async Task WhenWeDoAGetWithId_WeRetrieve_ASingleUnitOfMeasure()
        {
            //Arrange
            int existingUnitsOfMeasure = 34;

            //Act
            UnitOfMeasureModel returnedUnitOfMeasure = new UnitOfMeasureModel();
            var result = await unitOfMeasureController.GetById(existingUnitsOfMeasure);
            result.TryGetContentValue(out returnedUnitOfMeasure);

            //Assert
            Assert.IsNotNull(returnedUnitOfMeasure);
            Assert.IsTrue(returnedUnitOfMeasure.Id == existingUnitsOfMeasure);
        }
コード例 #3
0
        public void ADD_GivenAUnitOfMeasureModel_WhenTheBusinessModelIsAddedBe_EnsureThatItIsAddedToTheDatabase()
        {
            //Arrange
            UnitOfMeasureModel newUnitOfMeasureModel = new UnitOfMeasureModel
            {
                Amount = 12.1,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Joe Bloggs",
                ModifiedBy = "Sam Smith",
                ModifiedDateTime = DateTime.Now,
                UnitType = "Spoons"
            };

            //Act
            var result = manager.Add(newUnitOfMeasureModel);
            repository.Commit();

            //
            Assert.IsInstanceOfType(result, typeof(UnitOfMeasureModel));
        }
        public async Task WhenWeDoAPost_WeAddARecipe_AndWeWantToBeSureThatTheRecipeIsReturned()
        {
            //Arrange       
            UnitOfMeasureModel newUnitOfMeasure = new UnitOfMeasureModel
            {
                Amount = 12,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Sam Smith",
                ModifiedBy = "Kat Brogan",
                ModifiedDateTime = DateTime.Now,
                UnitType = "Spoons",
                 
            };

            //Act
            UnitOfMeasureModel addedUnitOfMeasure = new UnitOfMeasureModel();
            var result = await unitOfMeasureController.Add(newUnitOfMeasure);
            result.TryGetContentValue(out addedUnitOfMeasure);

            //Assert
            Assert.IsNotNull(addedUnitOfMeasure);
            Assert.AreEqual(addedUnitOfMeasure.GetType(), typeof(UnitOfMeasureModel));
            Assert.IsTrue(addedUnitOfMeasure.Id > 1);
        }
コード例 #5
0
        public void UPDATE_GivenAnExistingUnitOfMeasure_UpdateTheAmount()
        {
            //Arrange
            UnitOfMeasureModel newUnitOfMeasureModel = new UnitOfMeasureModel
            {
                Id = 19,
                Amount = 12.69,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Joe Bloggs",
                ModifiedBy = "Sam Smith",
                ModifiedDateTime = DateTime.Now,
                UnitType = "Spoons"
            };

            //Act
            var result = manager.Update(newUnitOfMeasureModel);

            //Assert
            Assert.IsInstanceOfType(result, typeof(UnitOfMeasureModel));
            Assert.IsNotNull(result);
        }
コード例 #6
0
 public async Task<UnitOfMeasureModel> UpdateAsync(UnitOfMeasureModel unitOfMeasure)
 {
     return await _unitOfMeasureManager.UpdateAsync(unitOfMeasure);
 }
コード例 #7
0
 public async Task<UnitOfMeasureModel> AddAsync(UnitOfMeasureModel unitOfMeasure)
 {
     return await _unitOfMeasureManager.AddAsync(unitOfMeasure);
 }
        public async Task WhenWeDoAPut_TheUnitOfMeasureGetsUpdated()
        {
            //Arrange       
            UnitOfMeasureModel existingUnitOfMeasure = new UnitOfMeasureModel
            {
                Id = 16,
                Amount = 12,
                CreateDateTime = DateTime.Now,
                CreatedByAuthor = "Updated Unit Of Measure!!",
                ModifiedBy = "Kat Brogan",
                ModifiedDateTime = DateTime.Now,
                UnitType = "Spoons",

            };

            //Act
            UnitOfMeasureModel changedUnitOfMeasureModel = new UnitOfMeasureModel() ;
            var result = await unitOfMeasureController.Update(existingUnitOfMeasure);
            result.TryGetContentValue(out changedUnitOfMeasureModel);

            //Arrange
            Assert.IsTrue(changedUnitOfMeasureModel.CreatedByAuthor == existingUnitOfMeasure.CreatedByAuthor);
            Assert.IsNotNull(changedUnitOfMeasureModel);
        }