using Xunit; using Newtonsoft.Json.Linq; namespace raven_integration { public class CommonValidation { // /// // /// Test business rule should be active on new // /// // [Fact] // public async Task BusinessRuleNewShouldBeActiveShouldWork() // { // //CREATE attempt with broken rules // dynamic d = new JObject(); // d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST PROJECT"); // d.created = DateTime.Now.ToString(); // d.dollarAmount = 1.11m; // d.active = false;//<--- BROKEN RULE new project must be active = true!! // d.usertype = 1; // // ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("Inventory"), d.ToString()); // Util.ValidateErrorCodeResponse(a, 2200, 400); // Util.ShouldContainValidationError(a, "Active", "2203"); // } /// /// Test business rule name should be unique /// [Fact] public async Task BusinessRuleNameMustBeUnique() { //CREATE attempt with broken rules dynamic d = new JObject(); d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST PROJECT"); d.notes = "blah"; d.created = DateTime.Now.ToString(); d.dollarAmount = 1.11m; d.active = true; d.usertype = 1; ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("BizAdmin"), d.ToString()); Util.ValidateDataReturnResponseOk(a); //Now try to create again with same name a = await Util.PostAsync("project", await Util.GetTokenAsync("BizAdmin"), d.ToString()); //2002 in-valid expected Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ShouldContainValidationError(a, "Name", "2206"); } /// /// /// [Fact] public async Task BusinessRuleNameRequired() { dynamic d = new JObject(); d.name = ""; d.created = DateTime.Now.ToString(); d.dollarAmount = 1.11m; d.active = true; d.usertype = 1; ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("BizAdmin"), d.ToString()); //2002 in-valid expected Util.ValidateErrorCodeResponse(a, 2200, 400); //This is a modelstate error so even though it would be a 2201 in other circumstances here it's a 2203 //Maybe a todo is to refine this a bit Util.ShouldContainValidationError(a, "Name", "2203"); } /// /// /// [Fact(Skip = "TODO: Implement after workorder tests working needs dated object to test")] public async Task BusinessRuleStartDateWithoutEndDateShouldError() { dynamic d = new JObject(); d.name = Util.Uniquify("BusinessRuleStartDateWithoutEndDateShouldError TEST"); d.created = DateTime.Now.ToString(); d.startDate = d.created; //NO END DATE ERRROR d.dollarAmount = 1.11m; d.active = true; d.usertype = 1; ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("BizAdmin"), d.ToString()); //2002 in-valid expected Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ShouldContainValidationError(a, "EndDate", "2201"); } /// /// /// [Fact(Skip = "TODO: Implement after workorder tests working needs dated object to test")] public async Task BusinessRuleEndDateWithoutStartDateShouldError() { dynamic d = new JObject(); d.name = Util.Uniquify("BusinessRuleEndDateWithoutStartDateShouldError TEST"); d.created = DateTime.Now.ToString(); d.endDate = d.created; //NO START DATE ERRROR d.dollarAmount = 1.11m; d.active = true; d.usertype = 1; ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("BizAdmin"), d.ToString()); //2002 in-valid expected Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ShouldContainValidationError(a, "StartDate", "2201"); } /// /// /// [Fact(Skip = "TODO: Implement after workorder tests working needs dated object to test")] public async Task BusinessRuleEndDateBeforeStartDateShouldError() { dynamic d = new JObject(); d.name = Util.Uniquify("BusinessRuleEndDateBeforeStartDateShouldError TEST"); d.created = DateTime.Now.ToString(); d.startDate = DateTime.Now.ToString(); d.endDate = DateTime.Now.AddHours(-1).ToString(); //NO START DATE ERRROR d.dollarAmount = 1.11m; d.active = true; d.usertype = 1; ApiResponse a = await Util.PostAsync("project", await Util.GetTokenAsync("BizAdmin"), d.ToString()); //2002 in-valid expected Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ShouldContainValidationError(a, "StartDate", "2207"); } /// /// /// [Fact] public async Task BusinessRuleEnumInvalidShouldError() { dynamic d = new JObject(); d.name = Util.Uniquify("BusinessRuleEnumInvalidShouldError TEST"); d.created = DateTime.Now.ToString(); d.active = true; d.usertype = -1;//<---BAD VALUE ApiResponse a = await Util.PostAsync("user", await Util.GetTokenAsync("BizAdmin"), d.ToString()); //2002 in-valid expected Util.ValidateErrorCodeResponse(a, 2200, 400); Util.ShouldContainValidationError(a, "UserType", "2203"); } //================================================== }//eoc }//eons