-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit tests for remaining Property parsers, serialization and helper i…
…tself
- Loading branch information
1 parent
9d2fcc1
commit 7c26360
Showing
11 changed files
with
539 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
FullCalendarMVC/FullCalendar.Tests/FullCalendarHelperTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace FullCalendar.Tests | ||
{ | ||
[TestFixture] | ||
public class FullCalendarHelperTests | ||
{ | ||
[Test] | ||
public void FullCalendar_FullParametersNotSet_DefaultHtmlShouldBeCorrectlyBuilt() | ||
{ | ||
HtmlHelper htmlHelper = null; | ||
IHtmlString target = htmlHelper.FullCalendar(); | ||
target.ToHtmlString().Should().Be("<div class=\"fc \" data-fc-ButtonIcons=\"{'prev':'left-single-arrow','next':'right-single-arrow','prevYear':'left-double-arrow','nextYear':'right-double-arrow'}\" data-fc-ThemeSystem=\"standard\" data-fc-ThemeButtonIcons=\"{'prev':'circle-triangle-w','next':'circle-triangle-e','prevYear':'seek-prev','nextYear':'seek-next'}\" data-fc-BootstrapGlyphicons=\"{'close':'glyphicon-remove','prev':'glyphicon-chevron-left','next':'glyphicon-chevron-right','prevYear':'glyphicon-backward','nextYear':'glyphicon-forward'}\" data-fc-FirstDay=\"0\" data-fc-IsRTL=\"false\" data-fc-Weekends=\"true\" data-fc-FixedWeekCount=\"true\" data-fc-WeekNumbers=\"false\" data-fc-WeekNumbersWithinDays=\"false\" data-fc-ShowNonCurrentDates=\"true\" data-fc-HandleWindowResize=\"true\" data-fc-AllDaySlot=\"true\" data-fc-SlotEventOverlap=\"true\" data-fc-NowIndicator=\"false\" data-fc-NavLinks=\"false\" data-fc-Selectable=\"false\" data-fc-SelectHelper=\"false\" data-fc-UnselectAuto=\"true\" data-fc-LazyFetching=\"true\" data-fc-ForceEventDuration=\"false\" data-fc-Editable=\"false\" data-fc-EventStartEditable=\"true\" data-fc-EventDurationEditable=\"true\" data-fc-DragOpacity=\"0.75\" data-fc-DragScroll=\"true\" data-fc-Droppable=\"false\"></div>"); | ||
} | ||
|
||
[Test] | ||
public void FullCalendar_NameIsSetInCalendarParameters_HtmlShouldContainIdAndName() | ||
{ | ||
HtmlHelper htmlHelper = null; | ||
IHtmlString target = htmlHelper.FullCalendar(settings => | ||
{ | ||
settings.Name = "test"; | ||
}); | ||
target.ToHtmlString().Should().Contain("id='test'"); | ||
target.ToHtmlString().Should().Contain("name='test'"); | ||
} | ||
} | ||
} |
113 changes: 113 additions & 0 deletions
113
...C/FullCalendar.Tests/Infrastructure/PropertyParsers/EventCollectionPropertyParserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Web.Script.Serialization; | ||
|
||
namespace FullCalendar.Infrastructure.PropertyParsers.Tests | ||
{ | ||
[TestFixture] | ||
public class EventCollectionPropertyParserTests | ||
{ | ||
[Test] | ||
public void AddPropertyToDictionary_ValueIsNull_PropertyIsNotAdded() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.Events)); | ||
FullCalendarParameters parameters = new FullCalendarParameters(); | ||
EventCollectionPropertyParser parser = new EventCollectionPropertyParser(property, null); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ValueIsInitializedAsNullArray_PropertyIsNotAdded() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.Events)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
Events = Events.AsArray(null) | ||
}; | ||
EventCollectionPropertyParser parser = new EventCollectionPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ValueIsInitializedAsEmptyArray_PropertyIsNotAdded() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.Events)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
Events = Events.AsArray(new List<Event>()) | ||
}; | ||
EventCollectionPropertyParser parser = new EventCollectionPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ValueIsInitializedAsNonEmptyArray_PropertyIsAddedAsSerializedObject() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.Events)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
Events = Events.AsArray(new List<Event> | ||
{ | ||
new Event() | ||
}) | ||
}; | ||
EventCollectionPropertyParser parser = new EventCollectionPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().Contain("data-fc-Events", "[{'id':0,'title':null,'allDay':null,'start':null,'end':null,'url':null,'className':null,'editable':false,'startEditable':true,'durationEditable':true,'rendering':null,'overlap':true,'constraint':null,'color':null,'backgroundColor':null,'borderColor':null,'textColor':null,'googleCalendarId':null,'additionalFields':null}]"); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ValueIsInitializedAsJsonFeed_UrlPropertyIsAdded() | ||
{ | ||
string url = "/Home/GetData"; | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.Events)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
Events = Events.AsJsonFeed(url) | ||
}; | ||
EventCollectionPropertyParser parser = new EventCollectionPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().Contain("data-fc-Events", url); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ValueIsInitializedAsFunction_FunctionPropertyIsAdded() | ||
{ | ||
string function = "function() { alert(''); }"; | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.Events)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
Events = Events.AsFunction(function) | ||
}; | ||
EventCollectionPropertyParser parser = new EventCollectionPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().Contain("data-fc-Events", function); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ValueIsInitializedAsGoogleCalendarFeed_GoogleCalendarPropertyIsSerialized() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.Events)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
Events = Events.AsGoogleCalendarFeed("[email protected]") | ||
}; | ||
EventCollectionPropertyParser parser = new EventCollectionPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().Contain("data-fc-Events", "{'googleCalendarId':'[email protected]'}"); | ||
} | ||
} | ||
} |
106 changes: 106 additions & 0 deletions
106
...rMVC/FullCalendar.Tests/Infrastructure/PropertyParsers/EventSourcesPropertyParserTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
using FluentAssertions; | ||
using NUnit.Framework; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Drawing; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Web.Script.Serialization; | ||
|
||
namespace FullCalendar.Infrastructure.PropertyParsers.Tests | ||
{ | ||
[TestFixture] | ||
public class EventSourcesPropertyParserTests | ||
{ | ||
[Test] | ||
public void AddPropertyToDictionary_ValueIsNull_PropertyIsNotAdded() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.EventSources)); | ||
FullCalendarParameters parameters = new FullCalendarParameters(); | ||
EventSourcesPropertyParser parser = new EventSourcesPropertyParser(property, null); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ListIsEmpty_PropertyIsNotAdded() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.EventSources)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
EventSources = new List<EventSource>() | ||
}; | ||
EventSourcesPropertyParser parser = new EventSourcesPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().BeEmpty(); | ||
} | ||
|
||
[Test] | ||
public void AddPropertyToDictionary_ListIsNotEmpty_ValuesIsAddedAsSerializedObject() | ||
{ | ||
PropertyInfo property = typeof(FullCalendarParameters).GetProperties().Single(x => x.Name == nameof(FullCalendarParameters.EventSources)); | ||
FullCalendarParameters parameters = new FullCalendarParameters | ||
{ | ||
EventSources = new List<EventSource> | ||
{ | ||
new EventSource | ||
{ | ||
Id = 1, | ||
BackgroundColor = Color.DarkGray, | ||
BorderColor = Color.Blue, | ||
TextColor = Color.Gold, | ||
ClassName = "test", | ||
Rendering = Rendering.Background, | ||
Constraint = new EventConstraint(new BusinessHour | ||
{ | ||
Dow = new List<DayOfWeek> { DayOfWeek.Thursday, DayOfWeek.Friday }, | ||
Start = TimeSpan.FromHours(10), | ||
End = TimeSpan.FromHours(15) | ||
}), | ||
AllDayDefault = true, | ||
Url = "/Home/GetDiaryEvents" | ||
}, | ||
new EventSource | ||
{ | ||
Id = 2, | ||
Events = Events.AsArray(new List<Event> | ||
{ | ||
new Event | ||
{ | ||
Id = 1, | ||
Title = "Title", | ||
AllDay = false, | ||
ClassName = "test-class", | ||
Constraint = new EventConstraint(new BusinessHour | ||
{ | ||
Dow = new List<DayOfWeek> { DayOfWeek.Thursday, DayOfWeek.Friday }, | ||
Start = TimeSpan.FromHours(10), | ||
End = TimeSpan.FromHours(15) | ||
}), | ||
Color = Color.DarkRed, | ||
AdditionalFields = new Dictionary<string, string> | ||
{ | ||
{ "description", "this is the description" }, | ||
{ "other", "this is another additional field" } | ||
} | ||
} | ||
}), | ||
Type = "POST", | ||
Error = "function() { }", | ||
Data = new Dictionary<string, string> | ||
{ | ||
{ "custom_param1", "something" }, | ||
{ "custom_param2", "somethingelse" } | ||
} | ||
} | ||
} | ||
}; | ||
EventSourcesPropertyParser parser = new EventSourcesPropertyParser(property, new JavaScriptSerializer()); | ||
Dictionary<string, string> target = new Dictionary<string, string>(); | ||
parser.AddPropertyToDictionary(parameters, ref target); | ||
target.Should().Contain("data-fc-EventSources", @"[{'id':1,'events':null,'color':null,'backgroundColor':'#A9A9A9','borderColor':'#0000FF','textColor':'#FFD700','className':'test','editable':false,'startEditable':true,'durationEditable':true,'rendering':'background','overlap':true,'constraint':{'dow':[4,5],'start':'10:00','end':'15:00'},'allDayDefault':true,'eventDataTransform':null,'url':'/Home/GetDiaryEvents','startParam':null,'endParam':null,'timezoneParam':null,'type':null,'success':null,'error':null,'cache':false,'data':null},{'id':2,'events':[{'id':1,'title':'Title','allDay':false,'start':null,'end':null,'url':null,'className':'test-class','editable':false,'startEditable':true,'durationEditable':true,'rendering':null,'overlap':true,'constraint':{'dow':[4,5],'start':'10:00','end':'15:00'},'color':'#8B0000','backgroundColor':null,'borderColor':null,'textColor':null,'googleCalendarId':null,'additionalFields':{'description':'this is the description','other':'this is another additional field'}}],'color':null,'backgroundColor':null,'borderColor':null,'textColor':null,'className':null,'editable':false,'startEditable':true,'durationEditable':true,'rendering':null,'overlap':true,'constraint':null,'allDayDefault':null,'eventDataTransform':null,'url':null,'startParam':null,'endParam':null,'timezoneParam':null,'type':'POST','success':null,'error':'function() { }','cache':false,'data':{'custom_param1':'something','custom_param2':'somethingelse'}}]"); | ||
} | ||
} | ||
} |
Oops, something went wrong.