private static MergedSnapshot CreateSnapshot(DateTime subscriptionStartDate, DateTime timestamp, bool channelExists, bool isSubscribed, DateTime?innerTimestamp = null) { var creatorChannels = new List <CreatorChannelsSnapshotItem> { new CreatorChannelsSnapshotItem(ChannelId2, 100) }; if (channelExists) { creatorChannels.Add(new CreatorChannelsSnapshotItem(ChannelId1, 100)); } var subscriberChannels = new List <SubscriberChannelsSnapshotItem> { new SubscriberChannelsSnapshotItem(ChannelId2, 100, subscriptionStartDate) }; if (isSubscribed) { subscriberChannels.Add(new SubscriberChannelsSnapshotItem(ChannelId1, 100, subscriptionStartDate)); } return(new MergedSnapshot( timestamp, new CreatorChannelsSnapshot(innerTimestamp ?? timestamp, CreatorId1, creatorChannels), CreatorFreeAccessUsersSnapshot.Default(innerTimestamp ?? timestamp, CreatorId1), new SubscriberChannelsSnapshot(innerTimestamp ?? timestamp, SubscriberId1, subscriberChannels), SubscriberSnapshot.Default(innerTimestamp ?? timestamp, SubscriberId1), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(innerTimestamp ?? timestamp, SubscriberId1))); }
public void WhenOneSnapshot_ItShouldReturnCostPeriod() { var defaultCreatorChannelsSnapshot = CreatorChannelsSnapshot.Default(Now, CreatorId1); var defaultCreatorGuestListSnapshot = CreatorFreeAccessUsersSnapshot.Default(Now, CreatorId1); var defaultSubscriberChannelsSnapshot = SubscriberChannelsSnapshot.Default(Now, SubscriberId1); var defaultSubscriberSnapshot = SubscriberSnapshot.Default(Now, SubscriberId1); var defaultCalculatedAccountBalanceSnapshot = CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now, UserId.Random()); var mergedSnapshots = new List <MergedSnapshot> { new MergedSnapshot( Now.AddHours(5), defaultCreatorChannelsSnapshot, defaultCreatorGuestListSnapshot, defaultSubscriberChannelsSnapshot, defaultSubscriberSnapshot, defaultCalculatedAccountBalanceSnapshot), }; this.costCalculator.Setup(v => v.Execute(It.IsAny <MergedSnapshot>(), creatorPosts)) .Returns <MergedSnapshot, IReadOnlyList <CreatorPost> >((s, p) => (int)Math.Round((s.Timestamp - Now).TotalHours + 10)); var expectedOutput = new List <CostPeriod> { new CostPeriod(Now.AddHours(5), Now.AddHours(10), 15), }; var result = this.target.Execute(Now, Now.AddHours(10), mergedSnapshots, creatorPosts); CollectionAssert.AreEqual(expectedOutput, result.ToList()); }
private static MergedSnapshot CreateSnapshot(DateTime timestamp) { return(new MergedSnapshot( timestamp, CreatorChannelsSnapshot.Default(Now, UserId.Random()), CreatorFreeAccessUsersSnapshot.Default(Now, UserId.Random()), SubscriberChannelsSnapshot.Default(Now, UserId.Random()), SubscriberSnapshot.Default(Now, UserId.Random()), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now, UserId.Random()))); }
private static List <MergedSnapshot> CreateMergedSnapshotResult() { return(new List <MergedSnapshot> { new MergedSnapshot( CreatorChannelsSnapshot.Default(Now, UserId.Random()), CreatorFreeAccessUsersSnapshot.Default(Now, UserId.Random()), SubscriberChannelsSnapshot.Default(Now, UserId.Random()), SubscriberSnapshot.Default(Now, UserId.Random()), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now, UserId.Random())) }); }
public void ItShouldReturnTheGivenSnapshots() { var now = DateTime.UtcNow; var input = new List <MergedSnapshot> { new MergedSnapshot( CreatorChannelsSnapshot.Default(now, UserId.Random()), CreatorFreeAccessUsersSnapshot.Default(now, UserId.Random()), SubscriberChannelsSnapshot.Default(now, UserId.Random()), SubscriberSnapshot.Default(now, UserId.Random()), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(now, UserId.Random())), }; Assert.AreSame(input, this.target.Execute(input)); }
public void WhenSingleSnapshot_WhenDateIsNotEndDate_ItShouldNotModifyCollection() { var input = new List <MergedSnapshot> { new MergedSnapshot( Now.AddDays(1), CreatorChannelsSnapshot.Default(Now, UserId.Random()), CreatorFreeAccessUsersSnapshot.Default(Now, UserId.Random()), this.subscriberChannels, SubscriberSnapshot.Default(Now, UserId.Random()), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now, UserId.Random())) }; var output = this.target.Execute(input); CollectionAssert.AreEqual(input, output.ToList()); }
public void WhenTwoSnapshots_WhenDatesOnEndDatesButStraddleEndDates_ItShouldModifyCollection() { var input = new List <MergedSnapshot> { new MergedSnapshot( Now, CreatorChannelsSnapshot.Default(Now, UserId.Random()), CreatorFreeAccessUsersSnapshot.Default(Now, UserId.Random()), this.subscriberChannels, SubscriberSnapshot.Default(Now, UserId.Random()), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now, UserId.Random())), new MergedSnapshot( Now.AddDays(21), CreatorChannelsSnapshot.Default(Now, UserId.Random()), CreatorFreeAccessUsersSnapshot.Default(Now, UserId.Random()), SubscriberChannelsSnapshot.Default(Now, UserId.Random()), SubscriberSnapshot.Default(Now, UserId.Random()), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now, UserId.Random())) }; var expected = new List <MergedSnapshot> { input[0], new MergedSnapshot( Now.AddDays(7), input[0].CreatorChannels, input[0].CreatorFreeAccessUsers, input[0].SubscriberChannels, input[0].Subscriber, input[0].CalculatedAccountBalance), new MergedSnapshot( Now.AddDays(14), input[0].CreatorChannels, input[0].CreatorFreeAccessUsers, input[0].SubscriberChannels, input[0].Subscriber, input[0].CalculatedAccountBalance), input[1], }; var output = this.target.Execute(input); CollectionAssert.AreEqual(expected, output.ToList()); }
public void WhenCreatorGuestListSnapshotHasInvalidCreatorId_ItShouldThrowAnException() { this.target.Execute( StartTimeInclusive, EndTimeExclusive, SubscriberId1, CreatorId1, new List <ISnapshot> { CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now.AddSeconds(1), CreatorId1), SubscriberChannelsSnapshot.Default(Now.AddSeconds(1), SubscriberId1), SubscriberChannelsSnapshot.Default(Now.AddSeconds(2), SubscriberId1), CreatorFreeAccessUsersSnapshot.Default(Now.AddSeconds(2), new UserId(Guid.NewGuid())), SubscriberSnapshot.Default(Now.AddSeconds(2), SubscriberId1), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now.AddSeconds(2), SubscriberId1), }); }
public void WhenSnapshotsAreUnorderedAndValid_ItShouldThrowAnException() { this.target.Execute( StartTimeInclusive, EndTimeExclusive, SubscriberId1, CreatorId1, new List <ISnapshot> { CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now.AddSeconds(1), CreatorId1), SubscriberChannelsSnapshot.Default(Now.AddSeconds(2), SubscriberId1), SubscriberChannelsSnapshot.Default(Now.AddSeconds(1), SubscriberId1), CreatorFreeAccessUsersSnapshot.Default(Now.AddSeconds(2), CreatorId1), SubscriberSnapshot.Default(Now.AddSeconds(2), SubscriberId1), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now.AddSeconds(2), SubscriberId1), }); }
public void WhenSnapshotsAreLessThanEndDate_ItShouldReturn() { this.target.Execute( StartTimeInclusive, EndTimeExclusive, SubscriberId1, CreatorId1, new List <ISnapshot> { CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now.AddSeconds(1), CreatorId1), SubscriberChannelsSnapshot.Default(Now.AddSeconds(1), SubscriberId1), SubscriberChannelsSnapshot.Default(Now.AddSeconds(2), SubscriberId1), CreatorFreeAccessUsersSnapshot.Default(Now.AddSeconds(2), CreatorId1), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now.AddSeconds(2), SubscriberId1), SubscriberSnapshot.Default(EndTimeExclusive.AddTicks(-1), SubscriberId1), }); }
public void WhenSubscriptionTimeStampIsNotUtc_ItShouldThrowAnException() { this.target.Execute( StartTimeInclusive, EndTimeExclusive, SubscriberId1, CreatorId1, new List <ISnapshot> { CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now, CreatorId1), CreatorChannelsSnapshot.Default(Now.AddSeconds(1), CreatorId1), SubscriberChannelsSnapshot.Default(Now.AddSeconds(1), SubscriberId1), new SubscriberChannelsSnapshot(Now.AddSeconds(2), SubscriberId1, new List <SubscriberChannelsSnapshotItem> { new SubscriberChannelsSnapshotItem(new ChannelId(Guid.NewGuid()), 100, DateTime.Now) }), CreatorFreeAccessUsersSnapshot.Default(Now.AddSeconds(2), CreatorId1), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now.AddSeconds(2), SubscriberId1), SubscriberSnapshot.Default(Now.AddSeconds(2), SubscriberId1), }); }
private static MergedSnapshot CreateSnapshot(DateTime subscriptionStartDate, DateTime timestamp, bool channel1Subscribed, bool channel2Subscribed, BillingWeekEndTimeType endTimeType, DateTime?innerTimestamp = null) { var creatorChannels = new List <CreatorChannelsSnapshotItem> { new CreatorChannelsSnapshotItem(ChannelId1, 100), new CreatorChannelsSnapshotItem(ChannelId2, 100) }; var subscriberChannels = new List <SubscriberChannelsSnapshotItem>(); var channel1StartDate = subscriptionStartDate; var channel2StartDate = subscriptionStartDate; if (endTimeType == BillingWeekEndTimeType.Channel1First) { channel2StartDate = channel2StartDate.AddMinutes(10); } else if (endTimeType == BillingWeekEndTimeType.Channel2First) { channel1StartDate = channel2StartDate.AddMinutes(10); } if (channel1Subscribed) { subscriberChannels.Add(new SubscriberChannelsSnapshotItem(ChannelId1, 100, channel1StartDate)); } if (channel2Subscribed) { subscriberChannels.Add(new SubscriberChannelsSnapshotItem(ChannelId2, 100, channel2StartDate)); } return(new MergedSnapshot( timestamp, new CreatorChannelsSnapshot(innerTimestamp ?? timestamp, CreatorId1, creatorChannels), CreatorFreeAccessUsersSnapshot.Default(innerTimestamp ?? timestamp, CreatorId1), new SubscriberChannelsSnapshot(innerTimestamp ?? timestamp, SubscriberId1, subscriberChannels), SubscriberSnapshot.Default(innerTimestamp ?? timestamp, SubscriberId1), CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(innerTimestamp ?? timestamp, SubscriberId1))); }
public void WhenSeriesOfSnapshots_ItShouldReturnCostPeriods() { var snapshots = new List <ISnapshot> { new CreatorChannelsSnapshot(Now.AddHours(1), CreatorId1, new List <CreatorChannelsSnapshotItem> { new CreatorChannelsSnapshotItem(new ChannelId(Guid.NewGuid()), 100) }), new CreatorFreeAccessUsersSnapshot(Now.AddHours(2), CreatorId1, new List <string> { "a", "b" }), new SubscriberChannelsSnapshot(Now.AddHours(3), SubscriberId1, new List <SubscriberChannelsSnapshotItem> { new SubscriberChannelsSnapshotItem(new ChannelId(Guid.NewGuid()), 100, Now) }), new CreatorFreeAccessUsersSnapshot(Now.AddHours(4), CreatorId1, new List <string> { "a", "b" }), new CreatorChannelsSnapshot(Now.AddHours(5), CreatorId1, new List <CreatorChannelsSnapshotItem> { new CreatorChannelsSnapshotItem(new ChannelId(Guid.NewGuid()), 100) }), new SubscriberChannelsSnapshot(Now.AddHours(5), SubscriberId1, new List <SubscriberChannelsSnapshotItem> { new SubscriberChannelsSnapshotItem(new ChannelId(Guid.NewGuid()), 100, Now) }), new SubscriberSnapshot(Now.AddHours(6), SubscriberId1, "email"), new SubscriberChannelsSnapshot(Now.AddHours(6), SubscriberId1, new List <SubscriberChannelsSnapshotItem> { new SubscriberChannelsSnapshotItem(new ChannelId(Guid.NewGuid()), 100, Now) }) }; var defaultCreatorChannelSnapshot = CreatorChannelsSnapshot.Default(Now, CreatorId1); var defaultCreatorGuestListSnapshot = CreatorFreeAccessUsersSnapshot.Default(Now, CreatorId1); var defaultSubscriberChannelSnapshot = SubscriberChannelsSnapshot.Default(Now, SubscriberId1); var defaultSubscriberSnapshot = SubscriberSnapshot.Default(Now, SubscriberId1); var defaultCalculatedAccountBalanceSnapshot = CalculatedAccountBalanceSnapshot.DefaultFifthweekCreditAccount(Now, UserId.Random()); var mergedSnapshots = new List <MergedSnapshot> { new MergedSnapshot( Now, defaultCreatorChannelSnapshot, defaultCreatorGuestListSnapshot, defaultSubscriberChannelSnapshot, defaultSubscriberSnapshot, defaultCalculatedAccountBalanceSnapshot), new MergedSnapshot( Now.AddHours(1), (CreatorChannelsSnapshot)snapshots[0], defaultCreatorGuestListSnapshot, defaultSubscriberChannelSnapshot, defaultSubscriberSnapshot, defaultCalculatedAccountBalanceSnapshot), new MergedSnapshot( Now.AddHours(2), (CreatorChannelsSnapshot)snapshots[0], (CreatorFreeAccessUsersSnapshot)snapshots[1], defaultSubscriberChannelSnapshot, defaultSubscriberSnapshot, defaultCalculatedAccountBalanceSnapshot), new MergedSnapshot( Now.AddHours(3), (CreatorChannelsSnapshot)snapshots[0], (CreatorFreeAccessUsersSnapshot)snapshots[1], (SubscriberChannelsSnapshot)snapshots[2], defaultSubscriberSnapshot, defaultCalculatedAccountBalanceSnapshot), new MergedSnapshot( Now.AddHours(4), (CreatorChannelsSnapshot)snapshots[0], (CreatorFreeAccessUsersSnapshot)snapshots[3], (SubscriberChannelsSnapshot)snapshots[2], defaultSubscriberSnapshot, defaultCalculatedAccountBalanceSnapshot), new MergedSnapshot( Now.AddHours(5), (CreatorChannelsSnapshot)snapshots[4], (CreatorFreeAccessUsersSnapshot)snapshots[3], (SubscriberChannelsSnapshot)snapshots[5], defaultSubscriberSnapshot, defaultCalculatedAccountBalanceSnapshot), new MergedSnapshot( Now.AddHours(6), (CreatorChannelsSnapshot)snapshots[4], (CreatorFreeAccessUsersSnapshot)snapshots[3], (SubscriberChannelsSnapshot)snapshots[7], (SubscriberSnapshot)snapshots[6], defaultCalculatedAccountBalanceSnapshot), }; this.costCalculator.Setup(v => v.Execute(It.IsAny <MergedSnapshot>(), creatorPosts)) .Returns <MergedSnapshot, IReadOnlyList <CreatorPost> >((s, p) => (int)Math.Round((s.Timestamp - Now).TotalHours + 10)); var expectedOutput = new List <CostPeriod> { new CostPeriod(Now.AddHours(0), Now.AddHours(1), 10), new CostPeriod(Now.AddHours(1), Now.AddHours(2), 11), new CostPeriod(Now.AddHours(2), Now.AddHours(3), 12), new CostPeriod(Now.AddHours(3), Now.AddHours(4), 13), new CostPeriod(Now.AddHours(4), Now.AddHours(5), 14), new CostPeriod(Now.AddHours(5), Now.AddHours(6), 15), new CostPeriod(Now.AddHours(6), Now.AddHours(10), 16), }; var result = this.target.Execute(Now, Now.AddHours(10), mergedSnapshots, creatorPosts); CollectionAssert.AreEqual(expectedOutput, result.ToList()); }