public void AddTimespanNameExists() { // Fill empty string parameters "" with auto-generated string. testEntityFactory.PopulateEmptyStrings = true; // Add test helpdesk. TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk(); // Check that helpdesk was created successfully. Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status); Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0); // Add timespan. TestDataTimeSpan timespanDataA = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID); // Check that timespan was created successfully. Assert.AreEqual(HttpStatusCode.OK, timespanDataA.Response.Status); Assert.IsTrue(timespanDataA.Response.SpanId > 0); using (helpdesksystemContext context = new helpdesksystemContext()) { var timespan = context.Timespans.FirstOrDefault(t => t.SpanId == timespanDataA.Response.SpanId); Assert.IsNotNull(timespan); } // Try to add another timspan with the same name TestDataTimeSpan timespanDataB = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID, timespanDataA.Request.Name); // Check that timespan was not created due to duplicate name. Assert.AreEqual(HttpStatusCode.BadRequest, timespanDataB.Response.Status); }
public TestDataTimeSpan AddTimeSpan(int?helpdeskID = null, string name = "", DateTime?startDate = null, DateTime?endDate = null) { var request = new AddTimeSpanRequest(); if (helpdeskID != null) { request.HelpdeskId = (int)helpdeskID; } if (name == "" && PopulateEmptyStrings) { request.Name = AlphaNumericStringGenerator.GetString(10); } else { request.Name = name; } if (startDate == null) { request.StartDate = DateTime.Now; } if (endDate == null) { request.EndDate = DateTime.Now; request.EndDate.AddDays(1); } var response = HelpdeskFacade.AddTimeSpan(request); TestDataTimeSpan data = new TestDataTimeSpan(request, response); return(data); }
public void UpdateTimespan() { // Fill empty string parameters "" with auto-generated string. testEntityFactory.PopulateEmptyStrings = true; // Add test helpdesk. TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk(); // Check that helpdesk was created successfully. Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status); Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0); // Add timespan. TestDataTimeSpan timespanData = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID); // Check that timespan was created successfully. Assert.AreEqual(HttpStatusCode.OK, timespanData.Response.Status); Assert.IsTrue(timespanData.Response.SpanId > 0); UpdateTimeSpanRequest updateTimespanRequest = new UpdateTimeSpanRequest() { Name = AlphaNumericStringGenerator.GetString(10), StartDate = new DateTime(2019, 01, 01), EndDate = new DateTime(2019, 06, 01), }; UpdateTimeSpanResponse updateTimespanResponse = testEntityFactory.HelpdeskFacade.UpdateTimeSpan(timespanData.Response.SpanId, updateTimespanRequest); Assert.AreEqual(HttpStatusCode.OK, updateTimespanResponse.Status); Assert.IsTrue(updateTimespanResponse.Result); using (helpdesksystemContext context = new helpdesksystemContext()) { var timespan = context.Timespans.FirstOrDefault(u => u.SpanId == timespanData.Response.SpanId); Assert.AreEqual(timespan.StartDate, updateTimespanRequest.StartDate); Assert.AreEqual(timespan.Name, updateTimespanRequest.Name); Assert.AreEqual(timespan.EndDate, updateTimespanRequest.EndDate); } }
public void UpdateTimespanNameExists() { // Fill empty string parameters "" with auto-generated string. testEntityFactory.PopulateEmptyStrings = true; // Add test helpdesk. TestDataHelpdesk helpdeskData = testEntityFactory.AddHelpdesk(); // Check that helpdesk was created successfully. Assert.AreEqual(HttpStatusCode.OK, helpdeskData.Response.Status); Assert.IsTrue(helpdeskData.Response.HelpdeskID > 0); // Add timespan. TestDataTimeSpan timespanDataA = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID); // Check that timespan was created successfully. Assert.AreEqual(HttpStatusCode.OK, timespanDataA.Response.Status); Assert.IsTrue(timespanDataA.Response.SpanId > 0); // Add another timespan TestDataTimeSpan timespanDataB = testEntityFactory.AddTimeSpan(helpdeskData.Response.HelpdeskID); // Check that timespan was created successfully. Assert.AreEqual(HttpStatusCode.OK, timespanDataB.Response.Status); Assert.IsTrue(timespanDataB.Response.SpanId > 0); // This request will try to update timespan B's name to be the same as A's name, which should fail. var updateTimespanRequest = new UpdateTimeSpanRequest() { Name = timespanDataA.Request.Name, StartDate = new DateTime(2019, 01, 01), EndDate = new DateTime(2019, 06, 01), }; var updateTimespanResponse = testEntityFactory.HelpdeskFacade.UpdateTimeSpan(timespanDataB.Response.SpanId, updateTimespanRequest); Assert.AreEqual(HttpStatusCode.BadRequest, updateTimespanResponse.Status); Assert.IsFalse(updateTimespanResponse.Result); }