public void ShouldFetchAllComplaintsFromDb(string title, string description)
        {
            // Arrange
            using var context = new ComplaintsContext(DbFixtureProvider.CreateNewContextOptions());
            var complaintService       = new ComplaintService(context);
            var complaintEntityEntries = new List <EntityEntry <ComplaintEntity> >();
            var complaintIds           = new List <int>();

            for (var i = 0; i < 5; i++)
            {
                complaintEntityEntries.Add(
                    context.Complaints.Add(new ComplaintEntity
                {
                    Title       = title,
                    Description = description
                }));
            }

            context.SaveChanges();

            // Act
            var complaintsInDb = complaintService.GetAll().ToList();

            // Assert
            Assert.Equal(complaintsInDb.Count, complaintEntityEntries.Count);
            foreach (var complaint in complaintEntityEntries)
            {
                Assert.NotNull(complaintsInDb.Find(x => x.Id == complaint.Entity.Id));
            }
        }
示例#2
0
 //GET: api/complaint
 public IHttpActionResult Get()
 {
     try
     {
         return(Ok(_complaintService.GetAll()));
     }
     catch (Exception ec)
     {
         return(BadRequest(ec.Message));
     }
 }
        public ActionResult Read([DataSourceRequest] DataSourceRequest request)
        {
            DataSourceResult result = _complaintService.GetAll().ToDataSourceResult(request);

            return(Json(result));
        }