This commit is contained in:
232
Widget/WidgetValidationTests.cs
Normal file
232
Widget/WidgetValidationTests.cs
Normal file
@@ -0,0 +1,232 @@
|
||||
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", "InvalidValue");
|
||||
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
/// <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.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", "NotUnique");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <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);
|
||||
Util.ShouldContainValidationError(a, "Name", "RequiredPropertyEmpty");
|
||||
|
||||
}
|
||||
|
||||
/// <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", "LengthExceeded", "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", "RequiredPropertyEmpty");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <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", "RequiredPropertyEmpty");
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <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", "StartDateMustComeBeforeEndDate");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public async void BusinessRuleEnumInvalidShouldError()
|
||||
{
|
||||
|
||||
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 = 99999;//<---BAD ROLE VALUE
|
||||
|
||||
//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", "InvalidValue");
|
||||
|
||||
}
|
||||
|
||||
//==================================================
|
||||
|
||||
}//eoc
|
||||
}//eons
|
||||
Reference in New Issue
Block a user