public void Create_WhenRecordExists_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new PartnersController(dataLayer)) { var newPartner = TestDataProvider.CreateNewPartner(); controller.Create(newPartner); controller.Create(newPartner); } }
public async Task Create_WhenRequestInvalid_ShouldReturnBadRequest() { // Arrange var request = new CreatePartnerCommand(); _controller.ModelState.AddModelError("any error", "any message"); // Act var response = await _controller.Create(request); // Assert response.Should().NotBeNull().And.BeOfType <BadRequestObjectResult>(); }
public void Create_Normally_ShouldReturn_Partner() { var newPartner = TestDataProvider.CreateNewPartner(); CreatedAtActionResult actionResult; Partner partner; using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new PartnersController(dataLayer)) { actionResult = (CreatedAtActionResult)controller.Create(newPartner); partner = (Partner)actionResult.Value; } Assert.AreEqual(actionResult.ActionName, "Get"); Assert.IsTrue( partner.Id > 0, $"Partner ID is expected to greater than 0. Actual: {partner.Id}."); Assert.AreEqual( newPartner.Name, partner.Name, $"Invalid partner name. Expected: \"{newPartner.Name}\", actual: \"{partner.Name}\"."); Assert.AreEqual( newPartner.Address, partner.Address, $"Invalid partner address. Expected: \"{newPartner.Address}\", actual: \"{partner.Address}\"."); }
public void Create_WhenNameNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new PartnersController(dataLayer)) controller.Create(new NewPartner { Name = null, Address = null }); }
public static Partner CreatePartner(this PartnersController controller, NewPartner newPartner) { var actionResult = (CreatedAtActionResult)controller.Create(newPartner); return((Partner)actionResult.Value); }
public void Create_WhenParamNull_ShouldThrow() { using (var dataLayer = DataLayerHelper.CreateDataLayer()) using (var controller = new PartnersController(dataLayer)) controller.Create(null); }