public void ApplyDiscountWillApplyDiscountWhenUserIsPreferred() { // Arrange var preferredCustomer = new StubUserContext(Role.PreferredCustomer); decimal productUnitPrice = 25m; decimal expectedUnitPrice = 23.75m; Product sut = CreateProduct(unitPrice: productUnitPrice); // Act var discount = sut.ApplyDiscountFor(preferredCustomer); // Assert Assert.Equal(expected: expectedUnitPrice, actual: discount.UnitPrice); }
public void SetupBeforeEachTest() { this.auditConfiguration = new AuditConfiguration(); this.dateTime = new StubDateTime(); this.userContext = new StubUserContext(); this.auditConfiguration .Audit <Audit>(c => c.CreatedDateTime, c => c.CreatedUserGuid, c => c.ModifiedDateTime, c => c.ModifiedUserGuid) .AuditCreated <AuditCreated>(c => c.CreatedDateTime, c => c.CreatedUserGuid) .AuditCreatedDateTime <AuditCreatedAtOnly>(c => c.CreatedDateTime) .AuditCreatedUserGuid <AuditCreatedByOnly>(c => c.CreatedUserGuid) .AuditModified <AuditModified>(c => c.ModifiedDateTime, c => c.ModifiedUserGuid) .AuditModifiedDateTime <AuditModifiedAtOnly>(c => c.ModifiedDateTime) .AuditModifiedUserGuid <AuditModifiedByOnly>(c => c.ModifiedUserGuid); this.unitOfWorkFactory = this.CreateUnitOfWorkFactory(this.auditConfiguration, this.dateTime, this.userContext); this.userGuid = Guid.Parse("623EE11A-D28F-41b4-A493-74368F648C8D"); this.userContext.UserGuid = this.userGuid; }
public void AppendsAuditEntryWithExpectedUserId() { // Arrange var context = new SpyCommerceContext(); var userContext = new StubUserContext { CurrentUserId = Guid.NewGuid() }; AuditingCommandServiceDecorator <object> sut = CreateAuditingDecorator <object>(userContext: userContext, context: context); // Act sut.Execute(command: new object()); // Assert Assert.Equal( expected: userContext.CurrentUserId, actual: GetAppendedAuditEntry(context).UserId); }
public void GetFeaturedProductsWillReturnCorrectProductsForNonPreferredUser() { var user = new StubUserContext(); var expectedProducts = new[] { new { Name = "Olives", UnitPrice = 24.5m }, new { Name = "Mushrooms", UnitPrice = 14.2m }, }; var featuredProducts = new[] { new Product { Name = "Olives", UnitPrice = 24.5m }, new Product { Name = "Mushrooms", UnitPrice = 14.2m } }; // Arrange var repository = new StubProductRepository { FeaturedProducts = featuredProducts }; var sut = new ProductService(repository, user); // Act var actualProducts = from p in sut.GetFeaturedProducts() select new { p.Name, p.UnitPrice }; // Assert Assert.True( condition: expectedProducts.SequenceEqual(actualProducts), userMessage: string.Join(", ", actualProducts.Select(p => p.ToString()))); }