public void GivenTheFollowingTaxRules(Table table) { _testTaxRules = table.CreateSet <TestTaxRule>() .Select(row => { try { return(new TestTaxRule { Id = row.Id, ActualEntity = (ITaxRule)(typeof(TaxRules).GetField(row.RuleName).GetValue(typeof(TaxRules))) }); } catch (Exception e) { throw new ArgumentOutOfRangeException($"No tax rule found with name '{row.RuleName}' "); } }); }
public void WhenTheFollowingItemsAreAdded(Table table) { var itemsForBasket = table.CreateSet <TestShoppingItem>() .Select(row => { var taxRules = GetTaxRulesFromIds(row.TaxRuleIds); return(new TestShoppingItem { Quantity = row.Quantity, ShoppingItem = CreateItem <DefaultShoppingItem>(row.Id, row.Name, row.UnitPrice.IntoDecimal(), taxRules) }); }); foreach (var item in itemsForBasket) { Func <object> addItem = () => _shoppingBasket.AddItem(item.ShoppingItem); if (String.IsNullOrEmpty(item.Quantity)) { _shoppingBasket.AddItem(item.ShoppingItem); } else { var isIntegerQuantity = int.TryParse(item.Quantity, out int quantity); if (!isIntegerQuantity) { throw new ArgumentOutOfRangeException("Quanity is not a valid integer."); } try { _shoppingBasket.AddItem(item.ShoppingItem, quantity); } catch (Exception e) { _exception = e; _invocation = addItem; } } } }
public void ThenOnlyTheFollowingNotificationsAreReceived(Table table) { var expectedNotifications = table.CreateSet <TestNotificationSummary>() .Select(row => { var user = _users.FirstOrDefault(u => u.Id == row.UserId); var notificationSystem = _testNotificationSystems.FirstOrDefault(n => n.CommunicationType == row.CommunicationType).ActualEntity; var updateType = row.UpdateType.ToEnum <UpdateType>(); var publisherType = Assembly.Load("ShoppingCart").GetTypes() .Where(t => typeof(ITotals).IsAssignableFrom(t) && t.BaseType is Object && t.GetMethod("ToString").Invoke(Activator.CreateInstance(t), new object[0]).ToString().ToLowerInvariant() == row.Publisher.ToLowerInvariant()) .FirstOrDefault(); var publisher = (ITotals)Activator.CreateInstance(publisherType); return(new NotificationSummary(user, notificationSystem, publisher, updateType)); }); var summaries = BasketDatabase.NotificationSummaries; BasketDatabase.NotificationSummaries.Should().BeEquivalentTo(expectedNotifications); }
public void GivenTheFollowingNotificationSystems(Table table) { _testNotificationSystems = table.CreateSet <TestNotificationSystem>() .Select(row => { var loggerType = Type.GetType($"ShoppingCart.Common.Loggers.{row.Logger}, ShoppingCart"); var logger = Activator.CreateInstance(loggerType, new object[0]); var genericType = Type.GetType($"ShoppingCart.Subscriptions.NotificationSystems.{row.NotificationSystemName}, ShoppingCart"); var notificationCreator = typeof(NotificationSystemFactory).GetMethod("CreateNotificationType"); var notificationSystem = (NotificationSystem)notificationCreator .MakeGenericMethod(genericType) .Invoke(typeof(NotificationSystemFactory), new object[] { row.CommunicationChannel, logger }); return(new TestNotificationSystem { Id = row.Id, NotificationSystemName = row.NotificationSystemName, ActualEntity = notificationSystem, CommunicationType = row.CommunicationType, CommunicationChannel = row.CommunicationChannel }); }).ToArray(); }