Skip to content

Commit

Permalink
Unit tests for remaining Property parsers, serialization and helper i…
Browse files Browse the repository at this point in the history
…tself
  • Loading branch information
RobertHajbok committed Dec 7, 2017
1 parent 9d2fcc1 commit 7c26360
Show file tree
Hide file tree
Showing 11 changed files with 539 additions and 4 deletions.
30 changes: 30 additions & 0 deletions FullCalendarMVC/FullCalendar.Tests/FullCalendar.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,34 @@
<Reference Include="FluentAssertions.Core, Version=4.19.4.0, Culture=neutral, PublicKeyToken=33f2691a05b67b6a, processorArchitecture=MSIL">
<HintPath>..\packages\FluentAssertions.4.19.4\lib\net40\FluentAssertions.Core.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
</Reference>
<Reference Include="nunit.framework, Version=3.9.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb, processorArchitecture=MSIL">
<HintPath>..\packages\NUnit.3.9.0\lib\net40\nunit.framework.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Web" />
<Reference Include="System.Web.Extensions" />
<Reference Include="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.Helpers.dll</HintPath>
</Reference>
<Reference Include="System.Web.Mvc, Version=3.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Mvc.3.0.50813.1\lib\net40\System.Web.Mvc.dll</HintPath>
</Reference>
<Reference Include="System.Web.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.Razor.1.0.20105.408\lib\net40\System.Web.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Deployment, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Deployment.dll</HintPath>
</Reference>
<Reference Include="System.Web.WebPages.Razor, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.WebPages.1.0.20105.408\lib\net40\System.Web.WebPages.Razor.dll</HintPath>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
</ItemGroup>
Expand All @@ -74,6 +96,7 @@
<Compile Include="Entities\VisibleRangeTests.cs" />
<Compile Include="Extensions\ColorExtensionsTests.cs" />
<Compile Include="Extensions\StringExtensionsTests.cs" />
<Compile Include="FullCalendarHelperTests.cs" />
<Compile Include="Infrastructure\ControlsBuilderTests.cs" />
<Compile Include="Infrastructure\EventsTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\ArrayPropertyParserTests.cs" />
Expand All @@ -88,12 +111,19 @@
<Compile Include="Infrastructure\PropertyParsers\DayOfWeekPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\DoublePropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\EnumPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\EventCollectionPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\EventSourcesPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\FloatPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\FunctionPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\IntegerPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\ObjectPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\StringPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\ThemeSystemPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\TimeSpanPropertyParserTests.cs" />
<Compile Include="Infrastructure\PropertyParsers\UnitPropertyParserTests.cs" />
<Compile Include="Mocks\ScriptIgnoreAttributeMock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Serialization\NullPropertiesConverterTests.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config">
Expand Down
31 changes: 31 additions & 0 deletions FullCalendarMVC/FullCalendar.Tests/FullCalendarHelperTests.cs
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'");
}
}
}
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]'}");
}
}
}
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'}}]");
}
}
}
Loading

0 comments on commit 7c26360

Please sign in to comment.