Beispiel #1
0
        public void GetStatus()
        {
            var result = _service.GetById("1");
            var actual = GetFakeData()[0];

            Assert.AreEqual(result.Name, actual.Name);
        }
Beispiel #2
0
        public void Should_Update_Existing_Status(int id)
        {
            var fakeContext = new FakeContext("UpdateStatus");

            fakeContext.FillWith <Status>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository   = new StatusRepository(context);
                var validator    = new StatusValidator();
                var service      = new StatusService(repository, validator);
                var curretStatus = service.GetById(id);

                curretStatus.Name = "Testing";
                service.Update(curretStatus);
                Assert.Equal("Testing", service.GetById(id).Name);
                repository.Dispose();
            }
        }
        public HttpResponseMessage GetById(int id)
        {
            try
            {
                StatusService svc = new StatusService();
                ItemResponse <StatusEntry> resp = new ItemResponse <StatusEntry>();
                resp.Item = svc.GetById(id);

                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
            }
        }
Beispiel #4
0
        public string GetById(int?id)
        {
            string jsonResponse;

            if (id.HasValue == true)
            {
                jsonResponse = _statusService.GetById(id.Value);
            }
            else
            {
                jsonResponse = "Please provide a valid id";
            }

            return(jsonResponse);
        }
Beispiel #5
0
        public void Should_Return_Right_Status_When_Find_By_Id(int id)
        {
            var fakeContext = new FakeContext("StatusById");

            fakeContext.FillWith <Status>();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var expected = fakeContext.GetFakeData <Status>().Find(x => x.Id == id);

                var repository = new StatusRepository(context);
                var validator  = new StatusValidator();
                var service    = new StatusService(repository, validator);
                var actual     = service.GetById(id);

                Assert.Equal(expected, actual, new StatusIdComparer());
                repository.Dispose();
            }
        }
Beispiel #6
0
        public void Should_Create_Correct_StatusDTO_Object(int id)
        {
            var fakeContext = new FakeContext("StatusDTOTest");

            fakeContext.FillWithAll();

            using (var context = new MainContext(fakeContext.FakeOptions))
            {
                var repository = new StatusRepository(context);
                var validator  = new StatusValidator();
                var service    = new StatusService(repository, validator);
                var mockMapper = new MapperConfiguration(cfg =>
                {
                    cfg.AddProfile <AutoMapperProfile>();;
                });
                var mapper = mockMapper.CreateMapper();

                var testStatus = service.GetById(id);
                var statusDTO  = mapper.Map <Status, StatusDTO>(testStatus);

                Assert.IsType <StatusDTO>(statusDTO);
                Assert.Equal(testStatus.Name, statusDTO.Name);
            }
        }