public void Test10TimingDifferenceOk() { const int NumTimes = 1000; const int NumTakes = 10; using (var db = new AdventureWorksLt2012()) { //SETUP var firstId = db.Customers.Select(x => x.CustomerID).First(); //ATTEMPT TimedDelegateDecompiler(NumTimes, db, NumTakes); TimedCheckIfItNeedsDecompile(NumTimes, db, NumTakes, false); TimedCheckIfItNeedsDecompile(NumTimes, db, NumTakes, true); TimedCheckIfItNeedsDecompile(NumTimes, db, NumTakes, false); TimedNormalAccess(NumTimes, db, NumTakes); TimedNormalAccessButCallDecompileAnyway(NumTimes, db, NumTakes); TimedDelegateDecompiler(NumTimes, db, NumTakes); TimedNormalAccess(NumTimes, db, NumTakes); TimedNormalAccessButCallDecompileAnyway(NumTimes, db, NumTakes); TimedDelegateDecompiler(NumTimes, db, NumTakes); //VERIFY } }
public void Test10ListCustomersViaLinqPartsNoNullOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var log = new List <string>(); var pageSize = 5; var pageNumber = 0; var realCustomers = db.Customers.Where(c => c.SalesOrderHeaders.Any()); var details = realCustomers.Select(x => new { x.CompanyName, ContactName = x.Title + " " + x.FirstName + " " + x.MiddleName + " " + x.LastName + " " + x.Suffix }); var filteredQuery = details.Where(x => x.CompanyName.Contains("Bike")); var pagedQuery = filteredQuery.OrderBy(x => x.CompanyName).Skip(pageSize * pageNumber).Take(pageSize); db.Database.Log = log.Add; //ATTEMPT var customers = pagedQuery.ToList(); //VERIFY customers.Count.ShouldBeGreaterThan(0); foreach (var line in log) { Console.WriteLine(line); } } }
private void CheckTotals(AdventureWorksLt2012 db) { var soh = db.SalesOrderHeaders.Include(x => x.SalesOrderDetails).SingleOrDefault(x => x.SalesOrderID == _salesOrderId); soh.SubTotal.ShouldEqual(soh.SalesOrderDetails.Sum(x => x.LineTotal)); soh.TaxAmt.ShouldEqual(0); }
public void Test05AddressCreateViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var setupService = new CreateSetupService(db); var service = new CreateService(db); var lastCustomer = db.Customers.AsNoTracking().Include(x => x.CustomerAddresses).OrderByDescending(x => x.CustomerID).First(); //ATTEMPT var dto = setupService.GetDto <CrudCustomerAddressDto>() .SetCustomerIdWhenCreatingNewEntry(lastCustomer.CustomerID); dto.AddressType = "Unit Test"; dto.Address.AddressLine1 = "Some street"; dto.Address.AddressLine2 = Guid.NewGuid().ToString("D"); dto.Address.City = "some town"; dto.Address.StateProvince = "a state"; dto.Address.CountryRegion = "the world"; dto.Address.PostalCode = "XXX 111"; var status = service.Create(dto); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); var newLastCustomer = db.Customers.AsNoTracking().Include(x => x.CustomerAddresses.Select(y => y.Address)).OrderByDescending(x => x.CustomerID).First(); newLastCustomer.CustomerAddresses.Count.ShouldEqual(lastCustomer.CustomerAddresses.Count + 1); newLastCustomer.CustomerAddresses.OrderByDescending(x => x.AddressID).First().Address.AddressLine2.ShouldEqual(dto.Address.AddressLine2); } }
public void Test10AddressDeleteNotPossibleViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var snap = new CustomerSnapShot(db); var service = new DeleteService(db); var addressUsedInTwoPlaces = db.Addresses.Include(x => x.CustomerAddresses) .AsNoTracking() .OrderByDescending(x => x.AddressID) .First(x => x.CustomerAddresses.Count > 0 && x.SalesOrderHeaders.Count > 0); //ATTEMPT var status = service.DeleteWithRelationships <CustomerAddress>(DeleteHelpers.DeleteAssociatedAddress, addressUsedInTwoPlaces.CustomerAddresses.First().CustomerID, addressUsedInTwoPlaces.AddressID); //VERIFY status.IsValid.ShouldEqual(false, status.Errors); status.Errors.Count.ShouldEqual(1); status.Errors.First().ErrorMessage.ShouldEqual("This operation failed because another data entry uses this entry."); snap.CheckSnapShot(db); } }
public void Test20ListCustomersViaAutoMapperOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var log = new List <string>(); var pageSize = 5; var pageNumber = 0; var config = new MapperConfiguration(cfg => cfg.CreateMap <Customer, TestListCustomerDto>() .ForMember(d => d.TotalAllOrders, opt => opt.MapFrom(c => c.SalesOrderHeaders.Sum(x => (decimal?)x.TotalDue) ?? 0))); var custs = db.Customers.ProjectTo <TestListCustomerDto>(config).Decompile(); var filteredQuery = custs.Where(x => x.CompanyName.Contains("Bike") && x.TotalAllOrders > 0); var pagedQuery = filteredQuery.OrderBy(x => x.CompanyName).Skip(pageSize * pageNumber).Take(pageSize); db.Database.Log = log.Add; //ATTEMPT var customers = pagedQuery.ToList(); //VERIFY customers.Count.ShouldBeGreaterThan(0); foreach (var line in log) { Console.WriteLine(line); } } }
public void CheckSnapShot(AdventureWorksLt2012 db, int customers = 0, int custAddressesChange = 0, int addressesChange = 0) { var newSnap = new CustomerSnapShot(db); newSnap.NumCustomers.ShouldEqual(NumCustomers + customers, "customers wrong"); newSnap.NumCustomerAddresses.ShouldEqual(NumCustomerAddresses + custAddressesChange, "CustomerAddresses wrong"); newSnap.NumAddresses.ShouldEqual(NumAddresses + addressesChange, "addresses wrong"); }
public void FixtureSetup() { //we do this to force EF setup otherwise the timing below fails using (var db = new AdventureWorksLt2012()) { db.ProductDescriptions.ToList(); } }
private static void TimedDelegateDecompiler(int NumTimes, AdventureWorksLt2012 db, int NumTakes) { using (var timer = new TimerToConsole("With DelegateDecompiler", NumTimes)) for (int i = 0; i < NumTimes; i++) { var item1 = db.Customers.Select(x => x.FullName).Take(NumTakes).Decompile().ToList(); } }
private static void TimedNormalAccess(int NumTimes, AdventureWorksLt2012 db, int NumTakes) { using (var timer = new TimerToConsole("Normal access", NumTimes)) for (int i = 0; i < NumTimes; i++) { var item1 = db.Customers.Select(c => c.Title + " " + c.FirstName + " " + c.LastName + " " + c.Suffix) .Take(NumTakes) .ToList(); } }
public void FixtureTearDown() { //we delete our unit test SaleOrderHeader using (var db = new AdventureWorksLt2012()) { var service = new DeleteService(db); var status = service.Delete <SalesOrderHeader>(_salesOrderId); status.ShouldBeValid(); } }
public void Test04ListCustomerSumOrdersOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT var customerSums = db.Customers.Select(c => c.SalesOrderHeaders.Sum(x => (decimal?)x.TotalDue)).ToList(); //VERIFY customerSums.Count.ShouldBeGreaterThan(0); } }
public void Test01ListCustomerOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT var customers = db.Customers.ToList(); //VERIFY customers.Count.ShouldBeGreaterThan(0); } }
public void Test01CustomerNormalFullNameOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT var list = db.Customers.Select(c => c.Title + " " + c.FirstName + " " + c.LastName + " " + c.Suffix).ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); } }
public void Test02CustomerWithComputedFullNameOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT var list = db.Customers.Select(x => x.FullName).Decompile().ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); } }
public void Test01ListCustomerOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var now = DateTime.Now; //ATTEMPT var list = db.Products.Where(x => x.SellStartDate < now && (now <= (x.SellEndDate ?? now))).ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); } }
public void Test05CustomerWithComputedHasSalesOrderOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT var list = db.Customers.Where(x => x.HasBoughtBefore).Decompile().ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); list.Count.ShouldBeLessThan(100); } }
public void Test10AddLineItemCheckHeaderOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT var newOrder = AddLineItem(db, 3); //VERIFY var soh = db.SalesOrderHeaders.Include(x => x.SalesOrderDetails).SingleOrDefault(x => x.SalesOrderID == _salesOrderId); soh.SalesOrderDetails.Count(x => x.SalesOrderDetailID == newOrder.SalesOrderDetailID).ShouldEqual(1); CheckTotals(db); } }
public void Test02ListSalesOrdersViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new ListService(db); //ATTEMPT var list = service.GetAll <ListSalesOrderDto>().ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); list[0].CustomerCompanyName.ShouldNotEqualNull(); } }
public void Test01ListOrderDetailViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new ListService(db); //ATTEMPT var list = service.GetAll <CrudSalesOrderDetailDto>().ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); list.First().ProductName.ShouldNotEqualNull(); } }
public void Test01CheckSetupWeHaveASalesOrderHeaderOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT //VERIFY _salesOrderId.ShouldBeGreaterThan(0); var soh = db.SalesOrderHeaders.SingleOrDefault(x => x.SalesOrderID == _salesOrderId); soh.ShouldNotEqualNull(); soh.ShipMethod.ShouldEqual("Unit Test"); } }
public void Test10AddressWithComputedFullAddressOk() { using (var db = new AdventureWorksLt2012()) { //SETUP //ATTEMPT var list = db.Addresses.Select(x => x.FullAddress).Decompile().ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); string.IsNullOrEmpty(list.First()).ShouldEqual(false); list.Any(x => x.Contains(", ,")).ShouldEqual(false); } }
public void Test05ListCustomersViaServiceProductCategoryIdNonNullOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new ListService(db); //ATTEMPT var list = service.GetAll <Product>().Computed().ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); list.Any(x => x.ProductCategoryIDNonNull != 0).ShouldEqual(true); } }
public void Test02AddressDetailViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new DetailService(db); var customerWithAddresses = db.Customers.Include(x => x.CustomerAddresses).First(x => x.CustomerAddresses.Count > 1); //ATTEMPT var status = service.GetDetail <CrudCustomerAddressDto>(customerWithAddresses.CustomerID, customerWithAddresses.CustomerAddresses.First().AddressID); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.Result.Address.ShouldNotEqualNull(); } }
public void Test11DetailCrudCustomersViaServiceAddressOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new DetailService(db); var customerWithOrders = db.Customers.First(x => x.CustomerAddresses.Any()); //ATTEMPT var status = service.GetDetail <CrudCustomerDto>(customerWithOrders.CustomerID); //VERIFY status.ShouldBeValid(); status.Result.CustomerAddresses.Count().ShouldBeGreaterThan(0); } }
public void Test05DetailSalesOrderViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new DetailService(db); var firstOrderHeader = db.SalesOrderHeaders.First(); //ATTEMPT var status = service.GetDetail <CrudSalesOrderDto>(firstOrderHeader.SalesOrderID); //VERIFY status.IsValid.ShouldEqual(true, status.Errors); status.Result.SalesOrderDetails.Count().ShouldBeGreaterThan(0); } }
public void Test05UpdateSetupOrderDetailViaServiceOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new UpdateSetupService(db); var firstOrderHeader = db.SalesOrderHeaders.First(); //ATTEMPT var status = service.GetOriginal <CrudSalesOrderDto>(firstOrderHeader.SalesOrderID); //VERIFY status.ShouldBeValid(); status.Result.ShipToOptions.KeyValueList.Count.ShouldBeGreaterThan(0); } }
private static void TimedCheckIfItNeedsDecompile(int NumTimes, AdventureWorksLt2012 db, int NumTakes, bool okToUseDecompileIfNeeded) { using (var timer = new TimerToConsole("Normal access, but checks if needed. Decompile " + (okToUseDecompileIfNeeded ? "was added" : "was NOT added"), NumTimes)) { var addDecompile = typeof(Customer).GetCustomAttribute <ComputedAttribute>() != null && okToUseDecompileIfNeeded; for (int i = 0; i < NumTimes; i++) { var expression = db.Customers.Select( c => c.Title + " " + c.FirstName + " " + c.LastName + " " + c.Suffix) .Take(NumTakes); var item1 = addDecompile ? expression.Decompile().ToList() : expression.ToList(); } } }
public void Test01ListCustomersCheckIsOnSaleOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new ListService(db); //ATTEMPT var list = service.GetAll <ListProductDto>().Computed().ToList(); //VERIFY list.Count.ShouldBeGreaterThan(0); list.Where(c => c.SellStartDate < DateTime.Today && (DateTime.Today <= (c.SellEndDate ?? DateTime.Today))).All(x => x.IsOnSale).ShouldEqual(true); list.Where(c => !(c.SellStartDate < DateTime.Today && (DateTime.Today <= (c.SellEndDate ?? DateTime.Today)))).All(x => x.IsOnSale).ShouldEqual(false); } }
public void Test10DetailCrudCustomersViaServiceHasSalesOrdersOk() { using (var db = new AdventureWorksLt2012()) { //SETUP var service = new DetailService(db); var customerWithOrders = db.Customers.Include(x => x.SalesOrderHeaders).First(x => x.SalesOrderHeaders.Any()); //db.Database.Log = Console.WriteLine; //ATTEMPT var status = service.GetDetail <CrudCustomerDto>(customerWithOrders.CustomerID); //VERIFY status.ShouldBeValid(); status.Result.HasBoughtBefore.ShouldEqual(true); } }