public void Should_Create_New_Status() { var fakeContext = new FakeContext("CreateNewStatus"); var fakeStatus = new Status(); fakeStatus.Name = "full name"; using (var context = new MainContext(fakeContext.FakeOptions)) { var repository = new StatusRepository(context); var mockValidator = new Mock <IValidator <Status> >(MockBehavior.Strict); mockValidator .Setup(x => x.Validate(fakeStatus)) .Returns(new FluentValidation.Results.ValidationResult()); var service = new StatusService(repository, mockValidator.Object); var actual = service.Create(fakeStatus); var id = actual.Id; Assert.NotEqual(0, id); repository.Dispose(); } }
public void Should_Delete_Status() { var fakeContext = new FakeContext("DeleteStatus"); 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 currentCount = context.Status.Count(); var newStatus = new Status(); newStatus.Name = "Testing"; service.Create(newStatus); var createdStatus = (from u in service.GetAll() where u.Id != 0 select u).FirstOrDefault(); Assert.NotEqual(0, currentCount); service.Delete(createdStatus.Id); Assert.Equal(currentCount, context.Status.Count()); repository.Dispose(); } }
public BllStatus CreateStatus(BllStatus entity) { using (ServiceDB serviceDB = new ServiceDB()) { IUnitOfWork uow = new UnitOfWork(serviceDB); IStatusService service = new StatusService(uow); return(service.Create(entity)); } }
public async Task <ActionResult <object> > Create([FromBody] StatusForm form) { try { return(await _statusService.Create(form)); } catch (Exception ex) { return(new ApiResponse(ex.Message)); } }