2017-12-03 01:27:00 +01:00
|
|
|
module test.calendarwebapp.testjsonexport;
|
|
|
|
|
2017-12-10 17:04:23 +01:00
|
|
|
import calendarwebapp.event;
|
2017-12-03 01:27:00 +01:00
|
|
|
import calendarwebapp.jsonexport;
|
|
|
|
|
2018-01-14 13:51:52 +01:00
|
|
|
import core.exception : AssertError;
|
|
|
|
|
2018-01-14 15:04:49 +01:00
|
|
|
import poodinis;
|
|
|
|
|
2018-01-14 13:51:52 +01:00
|
|
|
import std.algorithm.iteration : each;
|
2018-01-14 15:04:49 +01:00
|
|
|
import std.conv : to;
|
2018-01-14 13:51:52 +01:00
|
|
|
import std.datetime.date : Date, Month;
|
2017-12-10 17:04:23 +01:00
|
|
|
import std.exception : enforce;
|
|
|
|
import std.range.interfaces : InputRange, inputRangeObject;
|
2018-01-14 13:51:52 +01:00
|
|
|
import std.range.primitives : empty;
|
2017-12-10 17:04:23 +01:00
|
|
|
|
|
|
|
import unit_threaded;
|
2017-12-03 01:27:00 +01:00
|
|
|
|
2018-01-14 15:04:49 +01:00
|
|
|
@("JSONExporter.write with 0 events")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
2018-01-14 17:59:16 +01:00
|
|
|
exporter.write.each!(dayData => dayData.events.empty.shouldBeTrue);
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 15:04:49 +01:00
|
|
|
@("JSONExporter.write with 1 event")
|
2017-12-03 01:27:00 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2017-12-10 17:04:23 +01:00
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
2018-01-14 13:51:52 +01:00
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
auto eventStore = container.resolve!EventStore;
|
|
|
|
immutable event = Event("599090de97355141140fc698", Date(2018, 1, 14));
|
|
|
|
eventStore.addEvent(event);
|
|
|
|
exporter.write.each!(dayData => (dayData.year == 2018
|
2018-01-14 17:59:16 +01:00
|
|
|
&& dayData.month == Month.jan && dayData.day == 14) ? dayData.events.shouldEqual([event])
|
|
|
|
: dayData.events.empty.shouldBeTrue);
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 15:04:49 +01:00
|
|
|
@("JSONExporter.write with 2 events at the same date")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
auto eventStore = container.resolve!EventStore;
|
|
|
|
immutable event1 = Event("599090de97355141140fc698", Date(2018, 1, 14));
|
|
|
|
immutable event2 = Event("59cb9ad8fc0ba5751c0df02b", Date(2018, 1, 14));
|
|
|
|
eventStore.addEvent(event1);
|
|
|
|
eventStore.addEvent(event2);
|
|
|
|
exporter.write(Date(2018, 1, 14)).each!(dayData => (dayData.year == 2018
|
2018-01-14 17:59:16 +01:00
|
|
|
&& dayData.month == Month.jan && dayData.day == 14) ? dayData.events.shouldEqual([event1,
|
|
|
|
event2]) : dayData.events.empty.shouldBeTrue);
|
2018-01-14 15:04:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write with 2 events at different dates")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
auto eventStore = container.resolve!EventStore;
|
|
|
|
immutable event1 = Event("599090de97355141140fc698", Date(2018, 1, 14));
|
|
|
|
immutable event2 = Event("59cb9ad8fc0ba5751c0df02b", Date(2018, 1, 15));
|
|
|
|
eventStore.addEvent(event1);
|
|
|
|
eventStore.addEvent(event2);
|
|
|
|
exporter.write(Date(2018, 1, 14)).each!((dayData) {
|
|
|
|
immutable date = Date(dayData.year, dayData.month.to!int, dayData.day);
|
|
|
|
if (date == Date(2018, 1, 14))
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
dayData.events.shouldEqual([event1]);
|
2018-01-14 15:04:49 +01:00
|
|
|
}
|
|
|
|
else if (date == Date(2018, 1, 15))
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
dayData.events.shouldEqual([event2]);
|
2018-01-14 15:04:49 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
dayData.events.empty.shouldBeTrue;
|
2018-01-14 15:04:49 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write check date inbetween begin and end")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
DayData(2018, Month.jan, "Januar", 14, DayType.Holiday, [], "Sonntag", []).shouldBeIn(
|
|
|
|
exporter.write(Date(2018, 1, 14)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write check date at begin")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
DayData(2018, Month.jan, "Januar", 1, DayType.Workday, [], "Montag", []).shouldBeIn(
|
|
|
|
exporter.write(Date(2018, 1, 14)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write check date just after begin")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
DayData(2018, Month.jan, "Januar", 2, DayType.Workday, [], "Dienstag", []).shouldBeIn(
|
|
|
|
exporter.write(Date(2018, 1, 14)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write check date before begin")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
DayData(2017, Month.dec, "Dezember", 1, DayType.Holiday, [], "Sonntag", []).shouldNotBeIn(
|
|
|
|
exporter.write(Date(2018, 1, 14)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write check date at end")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
DayData(2018, Month.mar, "März", 31, DayType.Weekend, [], "Samstag", []).shouldBeIn(
|
|
|
|
exporter.write(Date(2018, 1, 14)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write check date just before end")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
DayData(2018, Month.mar, "März", 30, DayType.Workday, [], "Freitag", []).shouldBeIn(
|
|
|
|
exporter.write(Date(2018, 1, 14)));
|
|
|
|
}
|
|
|
|
|
|
|
|
@("JSONExporter.write check date after end")
|
|
|
|
@system unittest
|
|
|
|
{
|
|
|
|
auto container = new shared DependencyContainer();
|
|
|
|
container.register!(EventStore, StubEventStore);
|
|
|
|
container.register!JSONExporter;
|
|
|
|
auto exporter = container.resolve!JSONExporter;
|
|
|
|
DayData(2018, Month.apr, "April", 1, DayType.Holiday, [], "Sonntag", []).shouldNotBeIn(
|
|
|
|
exporter.write(Date(2018, 1, 14)));
|
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager with begin > end")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
DayDataManager(Date(2018, 1, 14), Date(2018, 1, 13)).shouldThrow!AssertError;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager with begin = end")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
DayDataManager(Date(2018, 1, 14), Date(2018, 1, 14)).shouldThrow!AssertError;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date < begin and 0 events")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 13)).shouldThrow;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date > end and 0 events")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 17)).shouldThrow;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date = end and 0 events")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 16)).shouldThrow;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date = begin and 0 events")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 14)).shouldEqual(DayData(2018,
|
2018-01-14 13:51:52 +01:00
|
|
|
Month.jan, "Januar", 14, DayType.Holiday, [], "Sonntag", []));
|
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with begin < date < end and 0 events")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 15)).shouldEqual(DayData(2018,
|
2018-01-14 13:51:52 +01:00
|
|
|
Month.jan, "Januar", 15, DayType.Workday, [], "Montag", []));
|
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date < begin and 1 event")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
2018-01-14 13:51:52 +01:00
|
|
|
immutable event = Event("599090de97355141140fc698", Date(2018, 1, 14));
|
2018-01-14 17:59:16 +01:00
|
|
|
dayDataManager.addEvent(event);
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 13)).shouldThrow;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date > end and 1 event")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
2018-01-14 13:51:52 +01:00
|
|
|
immutable event = Event("599090de97355141140fc698", Date(2018, 1, 14));
|
2018-01-14 17:59:16 +01:00
|
|
|
dayDataManager.addEvent(event);
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 17)).shouldThrow;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date = end and 1 event")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
2018-01-14 13:51:52 +01:00
|
|
|
immutable event = Event("599090de97355141140fc698", Date(2018, 1, 14));
|
2018-01-14 17:59:16 +01:00
|
|
|
dayDataManager.addEvent(event);
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 16)).shouldThrow;
|
2018-01-14 13:51:52 +01:00
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with date = begin and 1 event")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 15));
|
2018-01-14 13:51:52 +01:00
|
|
|
immutable event = Event("599090de97355141140fc698", Date(2018, 1, 14));
|
2018-01-14 17:59:16 +01:00
|
|
|
dayDataManager.addEvent(event);
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 14)).shouldEqual(DayData(2018,
|
2018-01-14 13:51:52 +01:00
|
|
|
Month.jan, "Januar", 14, DayType.Holiday, [event], "Sonntag", []));
|
|
|
|
}
|
|
|
|
|
2018-01-14 17:59:16 +01:00
|
|
|
@("DayDataManager.getDayData with begin < date < end and 1 event")
|
2018-01-14 13:51:52 +01:00
|
|
|
@system unittest
|
|
|
|
{
|
2018-01-14 17:59:16 +01:00
|
|
|
auto dayDataManager = DayDataManager(Date(2018, 1, 14), Date(2018, 1, 16));
|
2018-01-14 13:51:52 +01:00
|
|
|
immutable event = Event("599090de97355141140fc698", Date(2018, 1, 15));
|
2018-01-14 17:59:16 +01:00
|
|
|
dayDataManager.addEvent(event);
|
|
|
|
dayDataManager.getDayData(Date(2018, 1, 15)).shouldEqual(DayData(2018,
|
2018-01-14 13:51:52 +01:00
|
|
|
Month.jan, "Januar", 15, DayType.Workday, [event], "Montag", []));
|
2017-12-03 01:27:00 +01:00
|
|
|
}
|