public SuplementDTO SaveSuplement(Token token, SuplementDTO suplement) { var securityInfo = SecurityManager.EnsureAuthentication(token); var service = new SupplementService(Session, securityInfo, Configuration); return(service.SaveSuplement(suplement)); }
public PagedResult <SuplementDTO> GetSuplements(Token token, GetSupplementsParam param, PartialRetrievingInfo retrievingInfo) { var securityInfo = SecurityManager.EnsureAuthentication(token); var service = new SupplementService(Session, securityInfo, Configuration); return(service.GetSuplements(param, retrievingInfo)); }
public async Task IsSupplementExistingById_WithSupplementIdAndIsDeletedIsTrue_ShouldReturnTrue() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); ISupplementService supplementService = new SupplementService(database); // Act bool result = await supplementService.IsSupplementExistingById(secondSupplementId, true); // Assert result.Should().Be(true); }
public async Task TotalCommentAsync_ShouldSeeDeletedCommentsTrue_ShouldReturnAllComments() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); ISupplementService supplementService = new SupplementService(database); // Act int result = await supplementService.TotalCommentsAsync(firstSupplementId, true); // Assert result.Should().Be(2); }
public async Task IsSupplementExistingByIdAndName_WithOtherSupplementIdAndNonExistingSupplementName_ShouldReturnFalse() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); ISupplementService supplementService = new SupplementService(database); // Act bool result = await supplementService.IsSupplementExistingByIdAndName(firstSupplementId, nonExistingSupplementName); // Assert result.Should().Be(false); }
public HttpResponseMessage GetAll() { try { SupplementService svc = new SupplementService(); ItemsResponse <SupplementAddRequest> resp = new ItemsResponse <SupplementAddRequest>(); resp.Items = svc.SelectAll(); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Delete(int id) { try { SupplementService svc = new SupplementService(); svc.Delete(id); SuccessResponse resp = new SuccessResponse(); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public async Task GetDetailsByIdAsync_WithSupplementIdAndPage_ShouldReturnValidServiceModel() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); SupplementService supplementService = new SupplementService(database); // Act SupplementDetailsServiceModel result = await supplementService.GetDetailsByIdAsync(firstSupplementId, page); // Assert result.Name.Should().Be("Supplement 1"); result.CategoryName.Should().Be("Category 1"); result.SubcategoryName.Should().Be("Subcategory 1"); result.ManufacturerName.Should().Be("Manufacturer 1"); }
public async Task TotalCommentAsync_ShouldSeeDeletedCommentsTrue_ShouldReturnAllFalseComments() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Comments.Where(c => c.SupplementId == firstSupplementId).FirstOrDefault().IsDeleted = true; database.SaveChanges(); ISupplementService supplementService = new SupplementService(database); // Act int result = await supplementService.TotalCommentsAsync(firstSupplementId, false); // Assert result.Should().Be(1); }
public async Task TotalCountAsync_WithSearchToken_ShouldReturnValidCount() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); database.Supplements.Add(new Supplement { Id = 100, Name = "other" }); database.SaveChanges(); ISupplementService supplementService = new SupplementService(database); // Act int result = await supplementService.TotalCountAsync("supplement"); // Assert result.Should().Be(10); }
public async Task GetAllAdvancedListingAsync_WithSearchTokenAndWithPage_ShouldReturnPagedNotDeletedSupplements() { // Arrange FitStoreDbContext database = this.Database; DatabaseHelper.SeedData(database); SupplementService supplementService = new SupplementService(database); // Act IEnumerable <SupplementAdvancedServiceModel> result = await supplementService.GetAllAdvancedListingAsync("supplement", page); // Assert result.Count().Should().Be(6); result.First().Id.Should().Be(1); result.First().Name.Should().Be("Supplement 1"); result.First().IsDeleted.Should().Be(false); result.Last().Id.Should().Be(19); result.Last().Name.Should().Be("Supplement 19"); result.Last().IsDeleted.Should().Be(false); }
public HttpResponseMessage UpdateSupplement(SupplementAddRequest model) { try { if (ModelState.IsValid) { SupplementService svc = new SupplementService(); svc.Update(model); SuccessResponse resp = new SuccessResponse(); return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage InsertSupplement(SupplementAddRequest model) { try { if (ModelState.IsValid) { SupplementService svc = new SupplementService(); int?id = svc.Insert(model); ItemResponse <int?> resp = new ItemResponse <int?>(); resp.Item = id; return(Request.CreateResponse(HttpStatusCode.OK, resp)); } else { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public ActionResult GetSupplements(string type) { var service = new SupplementService(); return(Content(new JavaScriptSerializer().Serialize(service.GetSupplementsByType(type)))); }
public SupplementController(SupplementService supplementService) { _supplementService = supplementService; }