public static IEnumerable <TestQuote> CreateFakeDayMinuteQuotes(TestCompany company, int numDaysSkipped, TimeSpan endTime) { SystemTime.SetDateTime(DateTime.Now.AddDays(-1 * numDaysSkipped)); var dayQuotes = CreateFakeDayQuotes(null, 7); var minuteQuotes = CreateFakeMinuteQuotes(null, endTime); var quoteCounter = 1; foreach (var dayQuote in dayQuotes) { dayQuote.Id = quoteCounter++; dayQuote.Company = company; dayQuote.CompanyId = company.Id; yield return(dayQuote); } foreach (var minQuote in minuteQuotes) { minQuote.Id = quoteCounter++; minQuote.Company = company; minQuote.CompanyId = company.Id; yield return(minQuote); } SystemTime.ResetDateTime(); }
public static IEnumerable <TestQuote> CreateFakeMinuteQuotes(TestCompany company, TimeSpan endTime) { var marketOpen = new TimeSpan(9, 30, 0); var marketClose = new TimeSpan(15, 59, 0); if (marketOpen >= endTime) { yield break; } for (int i = 0; i <= Math.Min((int)(endTime - marketOpen).TotalMinutes, (int)(marketClose - marketOpen).TotalMinutes); i++) { yield return(new TestQuote() { Id = i + 1, Company = company, CompanyId = company?.Id ?? 0, Date = SystemTime.Now().Date.Add(marketOpen.Add(new TimeSpan(0, i, 0))), Close = NumberUtils.GenerateRandomNumber(1, 200), High = NumberUtils.GenerateRandomNumber(1, 200), Low = NumberUtils.GenerateRandomNumber(1, 200), Open = NumberUtils.GenerateRandomNumber(1, 200), Volume = NumberUtils.GenerateRandomNumber(1, 1000000), QuoteType = QuoteTypeEnum.OneMinute, TypeId = (int)QuoteTypeEnum.OneMinute, IsValid = CreatesValidQuotes }); } }
public void Update_WithNonExistingCompany_ThrowsException() { // Arrange var companyToUpdate = new TestCompany() { Id = 123 }; // Act _service.Update(companyToUpdate); }
public void Delete_T_WithNonExistingCompanyId_ThrowsException() { // Arrange var companyToDelete = new TestCompany() { Id = 123 }; // Act _service.Delete(companyToDelete); }
public void Delete_T_AfterDisposed_ThrowsException() { // Arrange var companyToDelete = new TestCompany() { Id = 123 }; _service.Dispose(); // Act _service.Delete(companyToDelete); }
public async Task Set_GivenEmptyStore_WhenItemsAddedAreEmpty_ThenTheKeyMustBeFoundAndContainsNoItems() { // arrange var emptyCollection = new TestCompany[] {}; // act await _cacheType1.SetAsync(emptyCollection); var allKeys = _database.ScanKeys(); // assert Assert.That(allKeys, Is.Empty); }
public void Add_AfterDisposed_ThrowsException() { // Arrange var companyToAdd = new TestCompany() { Id = 123 }; _service.Dispose(); // Act _service.Add(companyToAdd); }
public void GetCompanies_WithValidRepository_ReturnsCompanies() { // Arrange var companyToAdd = new TestCompany(999); _repository.Add(companyToAdd); // Act var companies = _service.GetCompanies(); // Assert Assert.IsNotNull(companies); Assert.IsTrue(companies.Count() == 1); }
public void FindCompanyById_WithInvalidId_ReturnsNull() { // Arrange var companyToAdd = new TestCompany() { Id = 123 }; _repository.Add(companyToAdd); // Act var company = _service.FindCompany(234); // Assert Assert.IsNull(company); }
public void Add_WithValidCompany_AddsCompanyToRepository() { // Arrange var companyToAdd = new TestCompany() { Id = 123 }; // Act _service.Add(companyToAdd); var addedCompany = _service.FindCompany(companyToAdd.Id); // Assert Assert.IsTrue(addedCompany == companyToAdd); }
public async Task RetrieveByUniqueIndex_WhenCompaniesNamesAreUpdated_ThenIndexedNamesAreCorrect() { // arrange await _cacheType1.SetAsync(TestCompany.AllCompanies); var updatedBoeing = new TestCompany(TestCompany.Boeing.Id, "new Boeing", TestCompany.Boeing.Category); var updatedEbay = new TestCompany(TestCompany.Ebay.Id, "new Ebay", TestCompany.Ebay.Category); // re-add Boeing & Ebay updated to expected result var expectedCompanies = TestCompany.AllCompanies .Except(new[] { TestCompany.Boeing, TestCompany.Ebay }) .Concat(new[] { updatedBoeing, updatedEbay }); // update Boeing & Ebay in the actual cache await _cacheType1.AddOrUpdateAsync(updatedBoeing); await _cacheType1.AddOrUpdateAsync(updatedEbay); // companies can be retrieved foreach (var expectedCompany in expectedCompanies) { // act var retrievedEntity = (await _cacheType1.GetItemsByIndexAsync <TestCompanyNameExtractor>(expectedCompany.Name)).Single(); var retrievedEntityId = (await _cacheType1.GetMasterKeysByIndexAsync <TestCompanyNameExtractor>(expectedCompany.Name)).Single (); // assert Assert.That(retrievedEntity, Is.EqualTo(expectedCompany)); Assert.That(retrievedEntityId, Is.EqualTo(expectedCompany.Id)); } // old names don't lead to results foreach (var oldCompany in new[] { TestCompany.Boeing, TestCompany.Ebay }) { // act var retrievedEntities = await _cacheType1.GetItemsByIndexAsync <TestCompanyNameExtractor>(oldCompany.Name); var retrievedEntityIds = await _cacheType1.GetMasterKeysByIndexAsync <TestCompanyNameExtractor>(oldCompany.Name); // assert Assert.That(retrievedEntities, Is.Empty); Assert.That(retrievedEntityIds, Is.Empty); } }
public void FindCompanyBySymbol_WithInvalidSymbol_ReturnsNull() { // Arrange var symbol = "AAPL"; var companyToAdd = new TestCompany() { Symbol = symbol }; _repository.Add(companyToAdd); // Act var company = _service.FindCompany("GPRO"); // Assert Assert.IsNull(company); }
public void Delete_T_WithValidCompanyId_DeletesCompanyInRepository() { // Arrange var companyToDelete = new TestCompany() { Id = 123 }; _service.Add(companyToDelete); // Act _service.Delete(companyToDelete); var deletedCompany = _service.FindCompany(companyToDelete.Id); // Assert Assert.IsNull(deletedCompany); }
public void FindCompanyBySymbol_WithValidSymbol_ReturnsCompany2() { // Arrange var symbol = "AAPL"; var companyToAdd = new TestCompany() { Symbol = symbol }; _repository.Add(companyToAdd); // Act var company = _service.FindCompany("aApL"); // Assert Assert.IsNotNull(company); Assert.IsTrue(company == companyToAdd); }
public void FindCompanyById_WithValidId_ReturnsCompany() { // Arrange var id = 123; var companyToAdd = new TestCompany() { Id = id }; _repository.Add(companyToAdd); // Act var company = _service.FindCompany(id); // Assert Assert.IsNotNull(company); Assert.IsTrue(company == companyToAdd); }
public void CalculateSalary(Employee employee, Company company, double salary) { "Given a company working Mo-Fr between 08:00-12:00 and 13:00-17:00" .x(() => company = TestCompany.Working() .On(DayOfWeek.Monday, DayOfWeek.Tuesday, DayOfWeek.Wednesday, DayOfWeek.Thursday, DayOfWeek.Friday) .Daily.From(08, 00).To(12, 00) .Daily.From(13, 00).To(17, 00).Company); "And an employee payed 30$ per hour" .x(() => employee = TestEmployee.Create() .WithContract(TestEmployeeContract.For(company).Earning(30).Per(TimeSpan.FromHours(1)))); "When the employee has worked November 2021" .x(() => salary = SalaryCalculator .CalculateSalary(employee, DateTime.Parse("2021-11-01"), DateTime.Parse("2021-12-01"))); "Then his salary is " .x(() => salary.Should().Be(5280)); }
public void Update_WithExistingValidCompany_UpdatesCompanyInRepository() { // Arrange var companyToUpdate = new TestCompany() { Id = 123 }; _service.Add(companyToUpdate); // Act companyToUpdate.Id = 234; _service.Update(companyToUpdate); var updatedCompany = _service.FindCompany(companyToUpdate.Id); // Assert Assert.IsTrue(companyToUpdate.Id == 234); }
public async Task RetrieveByUniqueIndex_WhenACompanyIsAdded_ThenItCanBeRetrieved() { // arrange var entity = new TestCompany { Name = "test", Id = "1", Category = "Cat" }; // act await _cacheType1.AddOrUpdateAsync(entity); var retrievedEntityId = (await _cacheType1.GetMasterKeysByIndexAsync <TestCompanyNameExtractor>(entity.Name)).FirstOrDefault(); var retrievedEntity = (await _cacheType1.GetItemsByIndexAsync <TestCompanyNameExtractor>(entity.Name)).FirstOrDefault(); // assert Assert.That(retrievedEntityId, Is.EqualTo(entity.Id)); Assert.That(retrievedEntity, Is.EqualTo(entity)); }
public static IEnumerable <TestQuote> CreateFakeDayQuotes(TestCompany company, int numDays, int numDaysSkipped) { for (int i = numDaysSkipped + 1; i <= numDays + numDaysSkipped; i++) { yield return(new TestQuote() { Id = i, Company = company, CompanyId = company?.Id ?? 0, Date = SystemTime.Now().AddDays((-1 * i)).Date, Close = NumberUtils.GenerateRandomNumber(1, 200), High = NumberUtils.GenerateRandomNumber(1, 200), Low = NumberUtils.GenerateRandomNumber(1, 200), Open = NumberUtils.GenerateRandomNumber(1, 200), Volume = NumberUtils.GenerateRandomNumber(1, 1000000), QuoteType = QuoteTypeEnum.Day, TypeId = (int)QuoteTypeEnum.Day, IsValid = CreatesValidQuotes }); } }
public void Initialize() { _mockDownloader = new MockMarketDownloader(); _downloader = _mockDownloader.Object; _fakeCompany = FakeCompaniesBuilder.CreateFakeCompanyAAPL(); }
public static IEnumerable <TestQuote> CreateFakeDayQuotes(TestCompany company, int numDays) { return(CreateFakeDayQuotes(company, numDays, 0)); }
private static string GetId(TestCompany company) => company.Id;