public void TestKLineDataIndex_DoIndex_Normal() { KLineData data_ = ResourceLoader.GetKLineData_1Min(); IKLineData data = data_.GetRange(0, 449); MockDataProvider provider = new MockDataProvider(); provider.DataPathDir = "testindex"; String targetPath = provider.GetDataPath() + "\\testindex.kline"; KLineDataStore store = new KLineDataStore(targetPath); store.Save(data); KLineDataIndexer indexer = new KLineDataIndexer(targetPath); indexer.DoIndex(); KLineDataIndexResult result = indexer.GetIndexResult(); Assert.AreEqual(2, result.DateList.Count); Assert.AreEqual(20131202, result.DateList[0]); Assert.AreEqual(20131203, result.DateList[1]); data = data_.GetRange(450, data_.Length - 1); store.Append(data); indexer.DoIndex(); result = indexer.GetIndexResult(); Assert.AreEqual(10, result.DateList.Count); Directory.Delete(provider.GetDataPath(), true); }
public async Task AddToBasket_ReturnsLaptopConfigurationList() { // Arrange var mockService = new Mock <ILaptopService>(); mockService.Setup(s => s.AddToBasket(It.IsAny <BasketItem>())) .ReturnsAsync(MockDataProvider.GetBasket()); var controller = new LaptopShopController(mockService.Object); // Act var result = await controller.AddToBasket(It.IsAny <BasketItem>()); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <BasketViewModel>(okResult.Value); Assert.NotNull(returnValue); var basketItems = Assert.IsType <List <BasketItems> >(returnValue.BasketItems); var basketItem = basketItems.FirstOrDefault(); Assert.NotNull(basketItem); Assert.NotNull(basketItem.Laptop); Assert.Equal("Dell", basketItem.Laptop.Name); var configurations = Assert.IsType <List <LaptopConfiguration> >(basketItem.LaptopConfigurations); var configuration = configurations.FirstOrDefault(); Assert.NotNull(configuration); Assert.Equal("8GB", configuration.Value); }
static void Main(string[] args) { MockDataProvider data = new MockDataProvider(); List <Person> persons = (data.GetPeople(20)); if (persons != null) { DataTable dt = new DataTable(); dt.Columns.AddRange(new DataColumn[4] { new DataColumn("ID", typeof(int)), new DataColumn("Firstname", typeof(string)), new DataColumn("Lastname", typeof(string)), new DataColumn("Title", typeof(string)) }); int ID = 1; foreach (Person p in persons) { dt.Rows.Add(ID, p.Firstname, p.Lastname, p.TitleOfCountesey); ID++; } Executor executor = new Executor(); executor.Execute("InsertPerson", dt); } Repository repository = new Repository(); PrintAll(repository.GetAll()); Console.ReadLine(); }
public async Task AddToBasket_ReturnsLaptopConfigurationList() { // Arrange var mockRepo = new Mock <ILaptopRepository>(); mockRepo.Setup(s => s.GetLaptopList()) .ReturnsAsync(MockDataProvider.GetMockLaptopList()); mockRepo.Setup(s => s.GetConfigurationList()) .ReturnsAsync(MockDataProvider.GetMockLaptopConfigurationList()); mockRepo.Setup(s => s.AddToBasket(It.IsAny <BasketItem>())) .ReturnsAsync(MockDataProvider.GetBasketItems()); var service = new LaptopService(mockRepo.Object); // Act var result = await service.AddToBasket(It.IsAny <BasketItem>()); // Assert var returnValue = Assert.IsType <BasketViewModel>(result); Assert.NotNull(returnValue); var basketItems = Assert.IsType <List <BasketItems> >(returnValue.BasketItems); var basketItem = basketItems.FirstOrDefault(); Assert.NotNull(basketItem); Assert.NotNull(basketItem.Laptop); Assert.Equal("Dell", basketItem.Laptop.Name); var configurations = Assert.IsType <List <LaptopConfiguration> >(basketItem.LaptopConfigurations); var configuration = configurations.FirstOrDefault(); Assert.NotNull(configuration); Assert.Equal((decimal)45.67, configuration.Price); }
public void LRCache() { var data = new Dictionary <int, int>() { { key1, val1 }, { key2, val2 }, { key3, val3 }, { key4, val4 } }; _provider = new MockDataProvider <int, int>(data); _cache = new LeastRecentCache <int, int>(_provider); _cache.ResizeCache(size); }
//[ClassInitialize] //public static void ClassInitialize(TestContext context) //{ // // TODO Use Moq framework. //} private static DataProviderBase GetMockDataProvider(Stack <String> eventStack) { // TODO Use Moq framework. var returnValue = new MockDataProvider(); returnValue.DataLoading += (sender, e) => eventStack.Push("DataLoading"); returnValue.DataLoaded += (sender, e) => eventStack.Push("DataLoaded"); return(returnValue); }
//[ClassInitialize] //public static void ClassInitialize(TestContext context) //{ // // TODO Use Moq framework. //} private static DataProviderBase GetMockDataProvider(Stack<String> eventStack) { // TODO Use Moq framework. var returnValue = new MockDataProvider(); returnValue.DataLoading += (sender, e) => eventStack.Push("DataLoading"); returnValue.DataLoaded += (sender, e) => eventStack.Push("DataLoaded"); return returnValue; }
public void List_WithValidCount_FromWebService() { //arrange int expectedAmount = 5; MockDataProvider data = new MockDataProvider(); //act int actualAmount = data.GetPeople(expectedAmount).Count; //assert Assert.AreEqual(expectedAmount, actualAmount); }
public async Task DeleteAsync_Test() { // arrange var data_provider = new MockDataProvider(); // act var task = data_provider.DeleteAsync(1); await task; // assert Assert.True(task.Status == TaskStatus.RanToCompletion); }
protected override void OnAuthorization(AuthorizationContext filterContext) { Authenticator auth = ApplicationSettings.Authenticator; if (auth != null) { //DataProvider = auth.DataProvider; DataProvider = new MockDataProvider(auth.DataProvider); CurrentUser = auth.User; filterContext.HttpContext.User = new CtsPrincipal(new CtsIdentity(CurrentUser)); } base.OnAuthorization(filterContext); }
public async Task ReadAsync_Test() { // arrange var data_provider = new MockDataProvider(); // act var products = await data_provider.ReadAsync(); // assert Assert.NotNull(products); Assert.Single(products); }
static void Main(string[] args) { MockDataProvider dataProvider = new MockDataProvider(); DataRepository repo = new DataRepository(); repo.Executor.Execute("dbo.MyProcedure1", repo.SqlCreater(dataProvider.GetPeople(10))); foreach (Person p in repo.GetAll()) { Console.WriteLine(p); } Console.ReadKey(); }
public void DataProviderTest() { var provider = new SQLiteDataProvider(@"..\..\resources\covid.db"); try { provider.ClearDayInfoData(); } catch (Exception) { // ignored } //Test insertion of CountryInfo list IDataProvider <CountryInfo> mockDataProvider = new MockDataProvider(); var list = mockDataProvider.GetCountryData(); provider.InsertCountryData(list); //Extract list of countryInfoEx var countryInfoExList = provider.GetCountryData(); foreach (var countryInfo in countryInfoExList) { var tuple = (countryInfo.Confirmed, countryInfo.Deaths, countryInfo.Recovered, countryInfo.Continent, countryInfo.Population); switch (countryInfo.Name) { case "Italy": Assert.AreEqual(tuple, (2, 0, 1, "Europe", 50_000_000)); break; case "USA": Assert.AreEqual(tuple, (18, 4, 0, "America", 300_000_000)); break; case "Romania": Assert.AreEqual(tuple, (25, 3, 1, "Europe", 19_000_000)); break; case "China": Assert.AreEqual(tuple, (80, 10, 5, "Asia", 1_000_000_000)); break; } } //Test extraction the most recent date Assert.AreEqual(new Date(1983, 11, 30), provider.GetTheMostRecentDateOfData()); }
static void Main(string[] args) { //Creates a instance of MockDataProvider so we can access the functions in it MockDataProvider dataProvider = new MockDataProvider(); //Create a instance of Reporsitory so we can call the database function Reporsitory executor = new Reporsitory(); //First it gets the results from dataProvider, and saves it all in the database. executor.Save((dataProvider.GetPeople(99))); //Calls a function to print all persons to the console PrintAll(executor.GetAll()); //Wait for user to press any key on the keyboard Console.ReadKey(); }
public async Task CreateAsync_Test() { // arrange var data_provider = new MockDataProvider(); var product = new Product { Name = "Other product", Description = "This is a cool product as well", Quantity = 100 }; // act var new_id = await data_provider.CreateAsync(product); // assert Assert.NotEqual(0, new_id); }
public async Task GetLaptopList_ReturnsLaptopList() { // Arrange await using var context = new LaptopShopContext(_options); await context.Laptops.AddRangeAsync(MockDataProvider.GetMockLaptopList()); await context.SaveChangesAsync(); // Act var result = await new LaptopRepository(context).GetLaptopList(); // Assert var returnValue = Assert.IsType <Laptop[]>(result); var laptop = returnValue.FirstOrDefault(); Assert.NotNull(laptop); Assert.Equal("Dell", laptop.Name); }
public void List_WithValidCount_DB() { //arrange int ammount = 5; MockDataProvider data = new MockDataProvider(); Reporsitory executor = new Reporsitory(); List <Person> personList = new List <Person>(); int expectedAmmount = 0; //act personList = data.GetPeople(ammount); expectedAmmount = personList.Count; executor.Save(personList); int actualAmmount = executor.GetAll().Count; //assert Assert.AreEqual(expectedAmmount, actualAmmount); }
public async Task ValidateAsync_Test() { // arrange var data_provider = new MockDataProvider(); var product = new Product { ID = 2, Name = "Product A", Description = "This is a cool product as well", Quantity = 100 }; // act var is_valid = await data_provider.ValidateAsync(product); // assert Assert.False(is_valid); }
public async Task GetConfigurationList_ReturnsLaptopConfigurationList() { var mockRepo = new Mock <ILaptopRepository>(); mockRepo.Setup(s => s.GetConfigurationList()) .ReturnsAsync(MockDataProvider.GetMockLaptopConfigurationList()); var service = new LaptopService(mockRepo.Object); // Act var result = await service.GetConfigurationList(); // Assert var returnValue = Assert.IsType <LaptopConfiguration[]>(result); var configuration = returnValue.FirstOrDefault(); Assert.NotNull(configuration); Assert.Equal("Ram", configuration.Name); Assert.Equal("8GB", configuration.Value); }
public async Task GetLaptopList_ReturnsLaptopList() { // Arrange var mockRepo = new Mock <ILaptopRepository>(); mockRepo.Setup(s => s.GetLaptopList()) .ReturnsAsync(MockDataProvider.GetMockLaptopList()); var service = new LaptopService(mockRepo.Object); // Act var result = await service.GetLaptopList(); // Assert var returnValue = Assert.IsType <Laptop[]>(result); var laptop = returnValue.FirstOrDefault(); Assert.NotNull(laptop); Assert.Equal("Dell", laptop.Name); }
public void SaveDataToFile() { string filePath = USER_FILE_TEST_PATH; // Change file path to testing file savingHelper.FilePath = filePath; // Firstly, delete if it is already exists TestUtils.DeleteFileIfExists(filePath); // Save data to a new file savingHelper.SaveMessagesToFile(MockDataProvider.GetMockMessages()); // Check whether the expected file is created succefully or not Assert.True(TestUtils.CheckFileExists(filePath)); // Check whether content is corret or not Assert.Equal(TestUtils.ReadFile(filePath), MockDataProvider.JSON); }
static void Main(string[] args) { MockDataProvider dataProvider = new MockDataProvider(); DataRepository repo = new DataRepository(); repo.Executor.Execute("dbo.MyProcedure", 2); List <Person> persons = dataProvider.GetPeople(9); repo.Save(persons); List <Person> personFromDatabase = repo.GetAll(); foreach (Person p in personFromDatabase) { Console.WriteLine(p); } Console.ReadKey(); }
public async Task UpdateAsync_Test() { // arrange var data_provider = new MockDataProvider(); var product = new Product { ID = 1, Name = "Other product", Description = "This is a cool product as well", Quantity = 100 }; // act var task = data_provider.UpdateAsync(product); await task; // assert Assert.True(task.Status == TaskStatus.RanToCompletion); }
public async Task LaptopList_ReturnsLaptopList() { // Arrange var mockService = new Mock <ILaptopService>(); mockService.Setup(s => s.GetLaptopList()) .ReturnsAsync(MockDataProvider.GetMockLaptopList()); var controller = new LaptopShopController(mockService.Object); // Act var result = await controller.LaptopList(); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <Laptop[]>(okResult.Value); var laptop = returnValue.FirstOrDefault(); Assert.NotNull(laptop); Assert.Equal("Dell", laptop.Name); }
public async Task ConfigurationList_ReturnsLaptopConfigurationList() { // Arrange var mockService = new Mock <ILaptopService>(); mockService.Setup(s => s.GetConfigurationList()) .ReturnsAsync(MockDataProvider.GetMockLaptopConfigurationList()); var controller = new LaptopShopController(mockService.Object); // Act var result = await controller.ConfigurationList(); // Assert var okResult = Assert.IsType <OkObjectResult>(result); var returnValue = Assert.IsType <LaptopConfiguration[]>(okResult.Value); var configuration = returnValue.FirstOrDefault(); Assert.NotNull(configuration); Assert.Equal("Ram", configuration.Name); Assert.Equal("8GB", configuration.Value); }
public void DatabaseCacheTest() { var provider = new MockDatabaseProvider(); var cacheSystem = new DatabaseCache(); cacheSystem.Attach(provider); IDataProvider <CountryInfo> mockDataProvider = new MockDataProvider(); cacheSystem.CountryInfoList = mockDataProvider.GetCountryData().ToList(); //Extract list of countryInfoEx var countryInfoExList = provider.GetCountryData(); foreach (var countryInfo in countryInfoExList) { var tuple = (countryInfo.Confirmed, countryInfo.Deaths, countryInfo.Recovered); switch (countryInfo.Name) { case "Italy": Assert.AreEqual(tuple, (2, 0, 1)); break; case "USA": Assert.AreEqual(tuple, (18, 4, 0)); break; case "Romania": Assert.AreEqual(tuple, (25, 3, 1)); break; case "China": Assert.AreEqual(tuple, (80, 10, 5)); break; } } }
public async Task AddToBasket_ReturnsLaptopConfigurationList() { // Arrange await using var context = new LaptopShopContext(_options); await context.Basket.AddRangeAsync(MockDataProvider.GetBasketItems()); await context.SaveChangesAsync(); // Act var item = new BasketItem { LaptopId = 2, LaptopConfigurationIdList = new List <int> { 1, 4, 5 } }; var result = await new LaptopRepository(context).AddToBasket(item); // Assert Assert.NotNull(result); Assert.IsType <Basket[]>(result); Assert.Equal(6, result.Length); Assert.Equal(2, result.Select(r => r.LaptopId).Distinct().Count()); }
/// <summary> /// Configures the available services for dependency injection. /// </summary> /// <param name="services">Service collection to register services with.</param> public void ConfigureServices(IServiceCollection services) { // Configure CORS services.AddCors(options => { options.AddPolicy(LOCAL_DEVELOPMENT_CORS_POLICY, builder => { builder.WithOrigins("http://localhost:8080") .AllowAnyHeader() .AllowAnyMethod() .AllowCredentials(); }); }); // Configure JWT-based auth services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters { ValidateIssuer = true, ValidateLifetime = true, ValidateAudience = false, ValidateIssuerSigningKey = true, ValidIssuer = Configuration.GetValue <string>("Jwt:Issuer"), IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration.GetValue <string>("Jwt:Secret"))) }; }); // Configure MVC services.AddMvc(); // Set up repositories if (Configuration.GetValue <bool>("Mocking:UseMockDataPersistence")) { MockDataProvider dataProvider = null; if (Configuration.GetValue <bool>("Mocking:SeedWithMockDataOnStartup")) { dataProvider = new MockDataProvider(new PasswordHashingService()); } services.AddSingleton <IPlatformConfigurationRepository>(new MockPlatformConfigurationRepository(dataProvider)); MockUserRepository userRepository = new MockUserRepository(dataProvider); services.AddSingleton <IReadOnlyUserRepository>(userRepository); services.AddSingleton <IUserRepository>(userRepository); MockBlogRepository blogRepository = new MockBlogRepository(dataProvider); services.AddSingleton <IReadOnlyBlogRepository>(blogRepository); services.AddSingleton <IBlogRepository>(blogRepository); services.AddSingleton <IPostRepository>(new MockPostRepository(dataProvider)); } else { services.AddSingleton <IUserRepository>(new SqlUserRepository(Configuration)); services.AddSingleton <IBlogRepository>(new SqlBlogRepository(Configuration)); services.AddSingleton <IPostRepository>(new SqlPostRepository(Configuration)); } // Set up services services.AddSingleton <PasswordHashingService>(); services.AddSingleton <AuthService>(); services.AddSingleton <PlatformConfigutationService>(); services.AddSingleton <UserService>(); services.AddSingleton <BlogService>(); }
static void Main(string[] args) { string pathToData = "DATA"; string pathToResults = "wynik.txt"; bool runOneTime = true; DirectoryInfo di = new DirectoryInfo(pathToData + "\\letterB"); using (var tw = new StreamWriter(pathToResults, true)) { foreach (var csv in di.GetFiles("*.csv")) { IDataProvider dataProvider = new MockDataProvider(); Classifier <string> classifier = new Classifier <string>(); var sampleData = dataProvider.GetTrainingData(pathToData, csv.Name, ExcludeType.b) as List <InformationModel>; classifier.Teach(sampleData); List <List <string> > values = new List <List <string> >(); values.AddRange(File.ReadAllLines(csv.FullName) .Skip(1) .Select(FromCsv) .ToList()); Dictionary <string, int> counter = new Dictionary <string, int>() { { "m", 0 }, { "f", 0 }, { "b", 0 } }; foreach (var list in values) { IDictionary <string, double> tempDict = classifier.Classify(list); double min = 0; string cat = ""; foreach (var item in tempDict) { if (min == 0 || min > item.Value) { min = item.Value; cat = item.Key; } } counter[cat]++; } foreach (var item in counter) { tw.Write("{1}; ", item.Key, item.Value); } tw.WriteLine(); if (runOneTime) { break; } } } }
public void SerializeData_ShouldReturnJSON_IfListIsValid() { string json = fileParser.SerializeData(MockDataProvider.GetMockMessages()); Assert.Equal(json, MockDataProvider.JSON); }
public void DeserializeData_ShouldReturnList_WhenJsonFormatIsValid() { Assert.Equal(fileParser.DeserializeData(MockDataProvider.JSON), MockDataProvider.GetMockMessages()); }