Files
raven-test-integration/Widget/WidgetValidationTests.cs
2020-01-07 21:16:20 +00:00

243 lines
8.0 KiB
C#

using System;
using Xunit;
using Newtonsoft.Json.Linq;
using FluentAssertions;
using System.Collections.Generic;
using System.Collections.Concurrent;
namespace raven_integration
{
public class WidgetValidationTest
{
// /// <summary>
// /// Test business rule should be active on new
// /// </summary>
// [Fact]
// public async void BusinessRuleNewShouldBeActiveShouldWork()
// {
// //CREATE attempt with broken rules
// dynamic d = new JObject();
// d.name = Util.Uniquify("ServerShouldDisAllowOwnerOnlyRightsUserToDeleteNonOwned TEST WIDGET");
// d.created = DateTime.Now.ToString();
// d.dollarAmount = 1.11m;
// d.active = false;//<--- BROKEN RULE new widget must be active = true!!
// d.roles = 0;
// //create via inventory full test user
// ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
// Util.ValidateErrorCodeResponse(a, 2200, 400);
// Util.ShouldContainValidationError(a, "Active", "2203");
// }
/// <summary>
/// Test business rule name should be unique
/// </summary>
[Fact]
public async void BusinessRuleNameMustBeUnique()
{
//CREATE attempt with broken rules
dynamic d = new JObject();
d.name = Util.Uniquify("BusinessRuleNameMustBeUnique TEST WIDGET");
d.notes = "blah";
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
d.created = DateTime.Now.ToString();
d.dollarAmount = 1.11m;
d.active = true;
d.roles = 0;
//create via inventory full test user
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
Util.ValidateDataReturnResponseOk(a);
//Now try to create again with same name
a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Name", "2206");
}
/// <summary>
///
/// </summary>
[Fact]
public async void BusinessRuleNameRequired()
{
dynamic d = new JObject();
d.name = "";
d.created = DateTime.Now.ToString();
d.dollarAmount = 1.11m;
d.active = true;
d.roles = 0;
//create via inventory full test user
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), 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");
}
/// <summary>
///
/// </summary>
[Fact]
public async void BusinessRuleNameLengthExceeded()
{
dynamic d = new JObject();
d.name = new string('A', 256); ;
d.created = DateTime.Now.ToString();
d.dollarAmount = 1.11m;
d.active = true;
d.roles = 0;
//create via inventory full test user
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Name", "2202", "255 max");
}
/// <summary>
///
/// </summary>
[Fact]
public async void 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.roles = 0;
//create via inventory full test user
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "EndDate", "2201");
}
/// <summary>
///
/// </summary>
[Fact]
public async void 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.roles = 0;
//create via inventory full test user
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "StartDate", "2201");
}
/// <summary>
///
/// </summary>
[Fact]
public async void 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.roles = 0;
//create via inventory full test user
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "StartDate", "2207");
}
/// <summary>
///
/// </summary>
[Fact]
public async void BusinessRuleEnumInvalidShouldError()
{
//Note: because of the way the flags work as powers of 2 and with the 1 being the first flag value, basically any value up to the "All" value will be valid
//because you can make any number from 0 to all using any combination of the flags so the only thing that will fail is less than zero or greater than All
//As of this last edit the total flags value of All for roles is 131071
dynamic d = new JObject();
d.name = Util.Uniquify("BusinessRuleEnumInvalidShouldError TEST");
d.created = DateTime.Now.ToString();
//NO END DATE ERRROR
d.dollarAmount = 1.11m;
d.active = true;
d.roles = -1;//<---BAD ROLE VALUE
d.Notes = "blah";
d.customFields = Util.WidgetRequiredCustomFieldsJsonString();
//create via inventory full test user
ApiResponse a = await Util.PostAsync("Widget", await Util.GetTokenAsync("InventoryFull"), d.ToString());
//2002 in-valid expected
Util.ValidateErrorCodeResponse(a, 2200, 400);
Util.ShouldContainValidationError(a, "Roles", "2203");
}
//==================================================
}//eoc
}//eons