public TestCasePlaySongSelect()
        {
            PlaySongSelect songSelect;

            if (manager == null)
            {
                var storage = new TestStorage(@"TestCasePlaySongSelect");

                var backingDatabase = storage.GetDatabase(@"client");
                backingDatabase.CreateTable <StoreVersion>();

                rulesets = new RulesetStore(backingDatabase);
                manager  = new BeatmapManager(storage, null, backingDatabase, rulesets);

                for (int i = 0; i < 100; i += 10)
                {
                    manager.Import(createTestBeatmapSet(i));
                }
            }

            Add(songSelect = new PlaySongSelect());

            AddStep(@"Sort by Artist", delegate { songSelect.FilterControl.Sort = SortMode.Artist; });
            AddStep(@"Sort by Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
            AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
            AddStep(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
        }
        public void TestDoublePersist()
        {
            TestStorage storage = new TestStorage();

            storage.AddUnspentOutput(new UnspentOutput(0, Hash1, 0, 100, new byte[16]));

            UnspentOutputsUpdate update = new UnspentOutputsUpdate(storage);

            update.Spend(Hash1, 0, Block1);
            update.Add(new UnspentOutput(1, Hash1, 0, 200, new byte[16]));
            update.Add(new UnspentOutput(1, Hash1, 1, 201, new byte[16]));
            update.Add(new UnspentOutput(1, Hash2, 0, 300, new byte[16]));

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100}));
            Assert.That(storage.SpentOutputs, Is.Empty);

            update.Persist();

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {200, 201, 300}));
            Assert.That(storage.SpentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100}));

            update.Persist();

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {200, 201, 300}));
            Assert.That(storage.SpentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100}));
        }
Exemplo n.º 3
0
 public void IdentityThrowsInvalidOperation()
 {
     TestStorage storage = new TestStorage();
     Assert.Throws<InvalidOperationException>(() => storage.ApplicationIdentity);
     Assert.Throws<InvalidOperationException>(() => storage.AssemblyIdentity);
     Assert.Throws<InvalidOperationException>(() => storage.DomainIdentity);
 }
Exemplo n.º 4
0
        private void load()
        {
            TestSongSelect songSelect = null;

            var storage = new TestStorage(@"TestCasePlaySongSelect");

            // this is by no means clean. should be replacing inside of OsuGameBase somehow.
            IDatabaseContextFactory factory = new SingletonContextFactory(new OsuDbContext());

            Dependencies.Cache(rulesets = new RulesetStore(factory));
            Dependencies.Cache(manager  = new BeatmapManager(storage, factory, rulesets, null, null)
            {
                DefaultBeatmap = defaultBeatmap = Beatmap.Default
            });

            void loadNewSongSelect(bool deleteMaps = false) => AddStep("reload song select", () =>
            {
                if (deleteMaps)
                {
                    manager.Delete(manager.GetAllUsableBeatmapSets());
                    Beatmap.SetDefault();
                }

                if (songSelect != null)
                {
                    Remove(songSelect);
                    songSelect.Dispose();
                }

                Add(songSelect = new TestSongSelect());
            });

            loadNewSongSelect(true);

            AddWaitStep(3);

            AddAssert("dummy selected", () => songSelect.CurrentBeatmap == defaultBeatmap);

            AddAssert("dummy shown on wedge", () => songSelect.CurrentBeatmapDetailsBeatmap == defaultBeatmap);

            AddStep("import test maps", () =>
            {
                for (int i = 0; i < 100; i += 10)
                {
                    manager.Import(createTestBeatmapSet(i));
                }
            });

            AddWaitStep(3);
            AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap);

            loadNewSongSelect();
            AddWaitStep(3);
            AddAssert("random map selected", () => songSelect.CurrentBeatmap != defaultBeatmap);

            AddStep(@"Sort by Artist", delegate { songSelect.FilterControl.Sort = SortMode.Artist; });
            AddStep(@"Sort by Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
            AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
            AddStep(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
        }
Exemplo n.º 5
0
        public Task <TaskResult> Execute(TaskInfo taskInfo, TestStorage storage)
        {
            var task = CreateTask(taskInfo);

            task.Storage = storage;
            return(task.Process(taskInfo));
        }
Exemplo n.º 6
0
        public override void Reset()
        {
            base.Reset();
            oldDb = Dependencies.Get <BeatmapDatabase>();
            if (db == null)
            {
                storage = new TestStorage(@"TestCasePlaySongSelect");
                db      = new BeatmapDatabase(storage);
                Dependencies.Cache(db, true);

                var sets = new List <BeatmapSetInfo>();

                for (int i = 0; i < 100; i += 10)
                {
                    sets.Add(createTestBeatmapSet(i));
                }

                db.Import(sets);
            }

            Add(songSelect = new PlaySongSelect());

            AddButton(@"Sort by Artist", delegate { songSelect.FilterControl.Sort = SortMode.Artist; });
            AddButton(@"Sort by Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
            AddButton(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
            AddButton(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
        }
Exemplo n.º 7
0
        private void load()
        {
            PlaySongSelect songSelect;

            if (manager == null)
            {
                var storage = new TestStorage(@"TestCasePlaySongSelect");

                // this is by no means clean. should be replacing inside of OsuGameBase somehow.
                var context = new OsuDbContext();

                Func <OsuDbContext> contextFactory = () => context;

                dependencies.Cache(rulesets = new RulesetStore(contextFactory));
                dependencies.Cache(manager  = new BeatmapManager(storage, contextFactory, rulesets, null));

                for (int i = 0; i < 100; i += 10)
                {
                    manager.Import(createTestBeatmapSet(i));
                }
            }

            Add(songSelect = new PlaySongSelect());

            AddStep(@"Sort by Artist", delegate { songSelect.FilterControl.Sort = SortMode.Artist; });
            AddStep(@"Sort by Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
            AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
            AddStep(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
        }
Exemplo n.º 8
0
 public void DomainIdentityIsSet(IsolatedStorageScope scope)
 {
     TestStorage storage = new TestStorage(scope);
     Assert.NotNull(storage.AssemblyIdentity);
     Assert.NotNull(storage.DomainIdentity);
     Assert.Throws<InvalidOperationException>(() => storage.ApplicationIdentity);
 }
Exemplo n.º 9
0
        public MainWindow()
        {
            InitializeComponent();
            var lst = new List <ArticleName> {
                new ArticleName {
                    id = "i", name = "xxx", description = "m", price = "p",
                }, new ArticleName {
                    id = "i", name = "xxx", description = "m", price = "p",
                }, new ArticleName {
                    id = "i", name = "xxx", description = "m", price = "p",
                }, new ArticleName {
                    id = "i", name = "xxx", description = "m", price = "p",
                }, new ArticleName {
                    id = "i", name = "xxx", description = "m", price = "p",
                }, new ArticleName {
                    id = "i", name = "xxx", description = "m", price = "p",
                }, new ArticleName {
                    id = "i", name = "xxx", description = "m", price = "p",
                }
            };

            //TestStorage.WriteXml<List<ArticleName>>(lst, "ArticleData.xml");
            articles = TestStorage.ReadXml <ObservableCollection <ArticleName> >("ArticleData.xml");
            Dgr_articles.ItemsSource = articles;



            //TestStorage.WriteXml<List<ArticleName>>(lst, "ArticleNameD.xml");
        }
        public void MaximumSizeThrowsInvalidOperation()
        {
            TestStorage storage = new TestStorage();
#pragma warning disable CS0618
            Assert.Throws<InvalidOperationException>(() => storage.MaximumSize);
#pragma warning restore CS0618
        }
        public void TestAdd()
        {
            TestStorage storage = new TestStorage();
            storage.AddUnspentOutput(new UnspentOutput(0, Hash1, 0, 100, new byte[16]));

            UnspentOutputsUpdate update = new UnspentOutputsUpdate(storage);

            Assert.Throws<InvalidOperationException>(() => update.Add(new UnspentOutput(0, Hash1, 0, 200, new byte[16])));
            update.Add(new UnspentOutput(0, Hash1, 1, 201, new byte[16]));
            update.Add(new UnspentOutput(0, Hash2, 0, 300, new byte[16]));
            update.Add(new UnspentOutput(0, Hash2, 1, 301, new byte[16]));

            Assert.Throws<InvalidOperationException>(() => update.Add(new UnspentOutput(0, Hash1, 0, 250, new byte[16])));
            Assert.Throws<InvalidOperationException>(() => update.Add(new UnspentOutput(0, Hash1, 1, 251, new byte[16])));
            Assert.Throws<InvalidOperationException>(() => update.Add(new UnspentOutput(0, Hash2, 0, 350, new byte[16])));
            Assert.Throws<InvalidOperationException>(() => update.Add(new UnspentOutput(0, Hash2, 1, 351, new byte[16])));

            Assert.That(update.FindUnspentOutputs(Hash1).Select(o => o.Sum).ToList(), Is.EquivalentTo(new ulong[] {100, 201}));
            Assert.That(update.FindUnspentOutputs(Hash2).Select(o => o.Sum).ToList(), Is.EquivalentTo(new ulong[] {300, 301}));
            Assert.That(update.FindUnspentOutput(Hash1, 0).Sum, Is.EqualTo(100));
            Assert.That(update.FindUnspentOutput(Hash1, 1).Sum, Is.EqualTo(201));
            Assert.That(update.FindUnspentOutput(Hash2, 0).Sum, Is.EqualTo(300));
            Assert.That(update.FindUnspentOutput(Hash2, 1).Sum, Is.EqualTo(301));

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100}));
            Assert.That(storage.SpentOutputs, Is.Empty);

            update.Persist();

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100, 201, 300, 301}));
            Assert.That(storage.SpentOutputs, Is.Empty);
        }
Exemplo n.º 12
0
        public override void Reset()
        {
            base.Reset();
            if (db == null)
            {
                storage = new TestStorage(@"TestCasePlaySongSelect");

                var backingDatabase = storage.GetDatabase(@"client");

                rulesets = new RulesetDatabase(storage, backingDatabase);
                db       = new BeatmapDatabase(storage, backingDatabase, rulesets);

                var sets = new List <BeatmapSetInfo>();

                for (int i = 0; i < 100; i += 10)
                {
                    sets.Add(createTestBeatmapSet(i));
                }

                db.Import(sets);
            }

            Add(songSelect = new PlaySongSelect());

            AddStep(@"Sort by Artist", delegate { songSelect.FilterControl.Sort = SortMode.Artist; });
            AddStep(@"Sort by Title", delegate { songSelect.FilterControl.Sort = SortMode.Title; });
            AddStep(@"Sort by Author", delegate { songSelect.FilterControl.Sort = SortMode.Author; });
            AddStep(@"Sort by Difficulty", delegate { songSelect.FilterControl.Sort = SortMode.Difficulty; });
        }
Exemplo n.º 13
0
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (storeData)
     {
         TestStorage.WriteXml <ObservableCollection <CustomerName> >(customers, "CustomerTest.xml");
     }
 }
Exemplo n.º 14
0
        public void TestUpload()
        {
            var test_storage = new TestStorage();
            var model = new GuiModel(test_storage);

            model.Connect();

            List<string> h_file_1 = new List<string>{ "hierarchy file one" };
            List<string> h_file_2 = new List<string>{ "hierarchy file two" };
            const string path_file_1 = "path file one";
            const string path_file_2 = "path file two";

            model.AddFileToUpload( h_file_1, path_file_1 );
            model.AddFileToUpload( h_file_2, path_file_2 );

            Assert.IsNull(test_storage.files_to_upload);

            model.Upload();

            Assert.AreEqual(2, test_storage.files_to_upload.Count );

            var test_so_1 = new StorageObject(h_file_1, path_file_1);
            var test_so_2 = new StorageObject(h_file_2, path_file_2);

            Assert.IsTrue(test_storage.files_to_upload.Exists( e => e.Equals(test_so_1) ) );
            Assert.IsTrue(test_storage.files_to_upload.Exists( e => e.Equals(test_so_2) ) );

            model.Upload();
            Assert.AreEqual(0, test_storage.files_to_upload.Count);
        }
Exemplo n.º 15
0
        private void AddTemplateTasks(TaskInfo task, TestInfo testInfo, TestStorage storage, string taskNamePrefix)
        {
            if (!(task is TemplateTaskInfo))
            {
                return;
            }

            var templateTask = (TemplateTaskInfo)task;

            if (templateTask.Parameters != null)
            {
                foreach (var parameter in templateTask.Parameters)
                {
                    var finalValue = Utilities.ConfigureUrl(parameter.Value);
                    storage.Cache.AddOrUpdate(parameter.Key, finalValue);
                }
            }
            var jsonTasks = GetTaskJsonData(templateTask.Name, "Templates");

            if (string.IsNullOrEmpty(jsonTasks))
            {
                Assert.Fail("No template file to include");
            }
            var tasks = JsonConvert.DeserializeObject <List <TaskActionInfo> >(jsonTasks, new TestJsonConverter());

            AddTasks(tasks, testInfo, $"{taskNamePrefix}{templateTask.Name}::SubTask");
        }
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     articleinfo = TestStorage.ReadXml <ObservableCollection <ArticleInfo> >("ArticleInfo.xml");
     //articleinfo = GenerateArticleInfo(20);
     //TestStorage.WriteXml<ObservableCollection<ArticleInfo>>(articleinfo, "ArticleInfo.xml");
     Lbx_articles.ItemsSource = articleinfo;
 }
Exemplo n.º 17
0
        public IActionResult ModifyTest([FromBody] TestStorage test)
        {
            test.PublishDate = DateTime.Now.ToString("yyyy-MM-dd");
            string type = HttpContext.Request.Query["type"];

            switch (type)
            {
            case "choice":
                test.Type = TestSort.choice.ToString();
                break;

            case "blank":
                test.Type = TestSort.blank.ToString();
                break;

            case "judege":
                test.Type = TestSort.judege.ToString();
                break;

            case "answer":
                test.Type = TestSort.answer.ToString();
                break;

            default:
                break;
            }
            Test.ModifyTest(test);
            return(Content("1"));
        }
Exemplo n.º 18
0
        private void OpenTests(object sender, RoutedEventArgs e)
        {
            var storage = new TestStorage(Path.GetFullPath(AppResources.PathTests),
                                          new XmlTestReader(), this.username);

            ShowHideWait(new Explorer(storage));
        }
 private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (storeData)
     {
         TestStorage.WriteXml <ObservableCollection <ArticleInfo> >(articleinfo, "ArticleInfo.xml");
     }
     Owner.Visibility = Visibility.Visible;
 }
Exemplo n.º 20
0
        public void DomainIdentityIsSet(IsolatedStorageScope scope)
        {
            TestStorage storage = new TestStorage(scope);

            Assert.NotNull(storage.AssemblyIdentity);
            Assert.NotNull(storage.DomainIdentity);
            Assert.Throws <InvalidOperationException>(() => storage.ApplicationIdentity);
        }
        public void MaximumSizeThrowsInvalidOperation()
        {
            TestStorage storage = new TestStorage();

#pragma warning disable CS0618
            Assert.Throws <InvalidOperationException>(() => storage.MaximumSize);
#pragma warning restore CS0618
        }
Exemplo n.º 22
0
        public void IdentityThrowsInvalidOperation()
        {
            TestStorage storage = new TestStorage();

            Assert.Throws <InvalidOperationException>(() => storage.ApplicationIdentity);
            Assert.Throws <InvalidOperationException>(() => storage.AssemblyIdentity);
            Assert.Throws <InvalidOperationException>(() => storage.DomainIdentity);
        }
Exemplo n.º 23
0
        public void Construct_NullBaseUri()
        {
            var expected      = new Uri(BlobStorage.DefaultBaseUri);
            var configuration = new TestConfiguration();

            var storage = new TestStorage(configuration);

            storage.BaseUri.Should().Be(expected);
        }
Exemplo n.º 24
0
        private TestStorage _calcStorage(TestPriceBase defaultPrice, int level, bool premium)
        {
            var buildCostUpdateModifer = 1.17;
            var storage = new TestStorage(level, _calcBuildPrice(defaultPrice, level, premium));;

            storage.CalcMaxStorable(premium, buildCostUpdateModifer);
            storage.CalcTransferLoses(premium);
            return(storage);
        }
Exemplo n.º 25
0
        public Task <TaskResult> Execute(TaskInfo task, TestStorage storage)
        {
            var seleniumTask = CreateTask(task, storage);

            seleniumTask.Storage          = storage;
            seleniumTask.HttpHelper       = _httpHelper;
            seleniumTask.ConsoleLogHelper = _consoleLogHelper;
            _logger.Debug($"[Browser:{seleniumTask.CurrentBrowser.Id}],[LogLocation:{seleniumTask.CurrentBrowser.ProfileLocation}]");
            return(seleniumTask.CheckDriver() ? seleniumTask.Process(task) : new TaskResult(false).Result());
        }
        public async Task ContainsGenericTypeNameInKey()
        {
            var          localStorageMock = new Mock <ILocalStorageService>();
            var          storage          = new TestStorage <string>(localStorageMock.Object);
            const string expectedKeyName  = "TestStorage<String>";

            await storage.EmptyRequest();

            localStorageMock.Verify(s => s.GetItemAsync <List <string> >(It.Is <string>(k => k == expectedKeyName), It.IsAny <CancellationToken?>()));
        }
        public async void Initializtion()
        {
            _storage = new TestStorage();

            await _storage.Write("string", "string");
            await _storage.Write("byte[]", new byte[] { 12, 23, 34 });
            await _storage.Write("stream", _stream);

            _storageProxy = new InMemoryStorageProxy(_storage, inMemory: false);
        }
Exemplo n.º 28
0
        public void TestDirectoryOrFile()
        {
            var test_storage = new TestStorage();
            var model = new GuiModel(test_storage);

            model.Connect();

            Assert.IsTrue(model.IsDirectory(test_storage.GetRootDir().GetName()));
            Assert.IsFalse(model.IsDirectory("second") );
        }
Exemplo n.º 29
0
        public async Task MqttServer_PersistRetainedMessage()
        {
            var storage       = new TestStorage();
            var serverAdapter = new TestMqttServerAdapter();
            var s             = new MqttFactory().CreateMqttServer(new[] { serverAdapter }, new MqttNetLogger());

            try
            {
                var options = new MqttServerOptions {
                    Storage = storage
                };

                await s.StartAsync(options);

                var c1 = await serverAdapter.ConnectTestClient(s, "c1");

                await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build());

                await c1.DisconnectAsync();
            }
            finally
            {
                await s.StopAsync();
            }

            await Task.Delay(TimeSpan.FromSeconds(2));

            // TODO: Find another way to wait for the retained components.

            s = new MqttFactory().CreateMqttServer(new[] { serverAdapter }, new MqttNetLogger());

            var receivedMessagesCount = 0;

            try
            {
                var options = new MqttServerOptions {
                    Storage = storage
                };
                await s.StartAsync(options);

                var c2 = await serverAdapter.ConnectTestClient(s, "c2");

                c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
                await c2.SubscribeAsync(new TopicFilterBuilder().WithTopic("retained").Build());

                await Task.Delay(500);
            }
            finally
            {
                await s.StopAsync();
            }

            Assert.AreEqual(1, receivedMessagesCount);
        }
Exemplo n.º 30
0
 public Buyer_Seller_2_()
 {
     InitializeComponent();
     //var lst = new List<CustomerName> { new CustomerName {  firstName = "xxx", lastName = "yyyy", Address = "zzz", Phone = "aaaa" },
     //    new CustomerName { firstName = "xxx", lastName = "yyyy", Address = "zzz", Phone = "aaaa"  },
     //    new CustomerName { firstName = "xxx", lastName = "yyyy", Address = "zzz", Phone = "aaaa"  },
     //    new CustomerName { firstName = "xxx", lastName = "yyyy", Address = "zzz", Phone = "aaaa"  }};
     //TestStorage.WriteXml<List<CustomerName>>(lst, "CustomerData.xml");
     customers = TestStorage.ReadXml <ObservableCollection <CustomerName> >("CustomerData.xml");
     Lbx_students.ItemsSource = customers;
 }
Exemplo n.º 31
0
        public void TestDownloadFile()
        {
            var test_storage = new TestStorage();
            var model = new GuiModel(test_storage);

            model.Connect();

            List<string> file_to_download = new List<string> { "/one/two/three" };
            model.DownloadFile( file_to_download, "" );
            Assert.AreEqual( file_to_download, test_storage.download_file );
        }
Exemplo n.º 32
0
        public async Task MqttServer_PersistRetainedMessage()
        {
            var storage       = new TestStorage();
            var serverAdapter = new TestMqttServerAdapter();
            var s             = new MqttFactory().CreateMqttServer(new[] { serverAdapter }, new MqttNetLogger());

            try
            {
                var options = new MqttServerOptions {
                    Storage = storage
                };

                await s.StartAsync(options);

                var c1 = await serverAdapter.ConnectTestClient("c1");

                await c1.PublishAndWaitForAsync(s, new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build());

                await Task.Delay(250);

                await c1.DisconnectAsync();
            }
            finally
            {
                await s.StopAsync();
            }

            Assert.AreEqual(1, storage.Messages.Count);

            s = new MqttFactory().CreateMqttServer(new[] { serverAdapter }, new MqttNetLogger());

            var receivedMessagesCount = 0;

            try
            {
                var options = new MqttServerOptions {
                    Storage = storage
                };
                await s.StartAsync(options);

                var c2 = await serverAdapter.ConnectTestClient("c2");

                c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
                await c2.SubscribeAsync(new TopicFilterBuilder().WithTopic("retained").Build());

                await Task.Delay(250);
            }
            finally
            {
                await s.StopAsync();
            }

            Assert.AreEqual(1, receivedMessagesCount);
        }
Exemplo n.º 33
0
        private void AssertStorageContains(TestStorage <StorageEventTableEntity> storage, Guid id, string data, DateTime?created = null, DateTime?deleted = null, DateTime?modified = null)
        {
            created  = created ?? TestCreateDate;
            modified = modified ?? TestNewEventDate;

            storage.ShouldContain(e =>
                                  e.RowKey == id.ToString() &&
                                  e.Created == created &&
                                  e.Modified == modified &&
                                  e.Deleted == deleted &&
                                  e.Data == data);
        }
Exemplo n.º 34
0
        public IActionResult AddTest([FromBody] TestStorage test)
        {
            test.PublishDate = DateTime.Now.ToString("yyyy-MM-dd");
            string type    = HttpContext.Request.Query["type"];
            string direct  = HttpContext.Request.Query["direct"];
            string account = HttpContext.Session.GetString("admin");

            test.Publisher = admin.GetByAccount(account).name;
            if (direct != "")
            {
                test.Grade = "exam";
            }
            switch (type)
            {
            case "choice":
                test.Type = TestSort.choice.ToString();
                break;

            case "blank":
                test.Type = TestSort.blank.ToString();
                break;

            case "judege":
                test.Type = TestSort.judege.ToString();
                break;

            case "answer":
                test.Type = TestSort.answer.ToString();
                break;

            default:
                break;
            }
            var a = Test.AddTest(test);

            if (a != null)
            {
                if (direct != "")
                {
                    Exam.AddTestToExam(new List <ExamContent>()
                    {
                        new ExamContent {
                            ExamId = Convert.ToInt32(direct), TestId = a.Id
                        }
                    });
                }
                return(Content("1"));
            }
            else
            {
                return(Content("0"));
            }
        }
Exemplo n.º 35
0
        public async void Initializtion()
        {
            _storage = new TestStorage();

            await _storage.Write("string", "string");

            await _storage.Write("byte[]", new byte[] { 12, 23, 34 });

            await _storage.Write("stream", _stream);

            _storageProxy = new InMemoryStorageProxy(_storage, inMemory: false);
        }
Exemplo n.º 36
0
        public async Task MqttServer_PersistRetainedMessage()
        {
            var storage       = new TestStorage();
            var serverAdapter = new TestMqttServerAdapter();

            var services = new ServiceCollection()
                           .AddLogging()
                           .AddMqttServer()
                           .AddSingleton <IMqttServerAdapter>(serverAdapter)
                           .BuildServiceProvider();

            var s = new MqttFactory(services).CreateMqttServer(options => options.Storage = storage);

            try
            {
                await s.StartAsync();

                var c1 = await serverAdapter.ConnectTestClient(s, "c1");

                await c1.PublishAsync(new MqttApplicationMessageBuilder().WithTopic("retained").WithPayload(new byte[3]).WithRetainFlag().Build());

                await c1.DisconnectAsync();
            }
            finally
            {
                await s.StopAsync();
            }

            await services.WaitForRetainedMessage("retained").TimeoutAfter(TimeSpan.FromSeconds(5));

            s = new MqttFactory(services).CreateMqttServer(options => options.Storage = storage);

            var receivedMessagesCount = 0;

            try
            {
                await s.StartAsync();

                var c2 = await serverAdapter.ConnectTestClient(s, "c2");

                c2.ApplicationMessageReceived += (_, __) => receivedMessagesCount++;
                await c2.SubscribeAsync(new TopicFilter("retained", MqttQualityOfServiceLevel.AtMostOnce));

                await Task.Delay(500);
            }
            finally
            {
                await s.StopAsync();
            }

            Assert.AreEqual(1, receivedMessagesCount);
        }
Exemplo n.º 37
0
        public void Construct_SlashedBaseUri()
        {
            var expected = new Uri("foo://bar/baz/", UriKind.Absolute);

            var configuration = new TestConfiguration
            {
                BaseUri = expected
            };

            var storage = new TestStorage(configuration);

            storage.BaseUri.Should().Be(expected);
        }
Exemplo n.º 38
0
 public Task <TaskResult> Execute(TaskInfo taskInfo, TestStorage storage)
 {
     try
     {
         var task = CreateTask(taskInfo);
         task.Storage = storage;
         return(task.Process(taskInfo));
     }
     catch (Exception ex)
     {
         _logger.Error($"Error: {ex.Message}");
         throw new Exception(ex.Message);
     }
 }
Exemplo n.º 39
0
        public void TestConnect()
        {
            var test_storage = new TestStorage();
            var model = new GuiModel(test_storage);

            Dictionary<string, List<string>> root = model.Connect();

            Assert.IsTrue(test_storage.connected);

            Assert.AreEqual(2, root.Count);
            Assert.IsTrue(root.Keys.ToList().Exists( e => TestStorageDir.root_element.GetName().Equals( e ) ) );
            Assert.IsTrue(root.Keys.ToList().Exists( e => TestStorageDir.second_element.GetName().Equals( e ) ) );

            Assert.IsTrue( root.Values.ToList().TrueForAll( e => e == null ) );
        }
Exemplo n.º 40
0
        public override void Reset()
        {
            base.Reset();
            oldDb = Dependencies.Get <BeatmapDatabase>();
            if (db == null)
            {
                storage = new TestStorage(@"TestCasePlaySongSelect");
                db      = new BeatmapDatabase(storage);
                Dependencies.Cache(db, true);

                var sets = new List <BeatmapSetInfo>();

                for (int i = 0; i < 100; i += 10)
                {
                    sets.Add(createTestBeatmapSet(i));
                }

                db.Import(sets);
            }
            Add(new PlaySongSelect());
        }
Exemplo n.º 41
0
        public void Correct_Items_Result_From_GetBy()
        {
            //Arrange
            #region TestObjects
            double doubleInputValue = 22;
            var testObject1 = new TestObject<string>()
            {
                Id = 1,
                Name = "Object1",
                RandomValue = doubleInputValue,
                SomeString = "String2",
                Stuff = new List<string>()
                    {
                        "Hahaha",
                        "wwwww",
                        "babababa",
                        "gaaab"
                    }
            };
            var testObject2 = new TestObject<string>()
            {
                Id = 2,
                Name = "Object1",
                RandomValue = doubleInputValue,
                SomeString = "String1",
                Stuff = new List<string>()
                    {
                        "Hahaha",
                        "Yayaya",
                        "hhhh",
                        "babababa",
                        "gaaab"
                    },
                dateTime = DateTime.Now
            };
            var testObject3 = new TestObject<string>()
            {
                Id = 1,
                Name = "Object2",
                RandomValue = 22.5,
                SomeString = "String2",
                Stuff = new List<string>()
                    {
                        "wwwww",
                    },
                dateTime = DateTime.Now
            };
            #endregion
            TestStorage<string> storage = new TestStorage<string>()
            {
                TestObjects = new List<TestObject<string>>()
                {
                    testObject1,
                    testObject2,
                    testObject3
                }.AsQueryable()
            };

            //Act
            var results = CollectionExtension.GetBy(storage.TestObjects, "RandomValue", doubleInputValue);

            //Assert
            AssertEqual(2, results.Count());
            foreach (object res in results)
            {
                var result = res as TestObject<string>;
                AssertEqual(doubleInputValue, result.RandomValue);
            }
        }
        public void SearchTest_Correct_Objects_Are_Found_Using_A_String_Property()
        {
            //Arrange
            #region TestObjects
            var testObject1 = new TestObject<string>()
            {
                Id = 1,
                Name = "Object1",
                RandomValue = 22,
                SomeString = "String2",
                Stuff = new List<string>()
                    {
                        "Hahaha",
                        "wwwww",
                        "babababa",
                        "gaaab"
                    }
            };
            var testObject2 = new TestObject<string>()
            {
                Id = 2,
                Name = "Object1",
                RandomValue = 22,
                SomeString = "String1",
                Stuff = new List<string>()
                    {
                        "Hahaha",
                        "Yayaya",
                        "hhhh",
                        "babababa",
                        "gaaab"
                    },
                dateTime = DateTime.Now
            };
            var testObject3 = new TestObject<string>()
            {
                Id = 1,
                Name = "Object2",
                RandomValue = 22.5,
                SomeString = "String2",
                Stuff = new List<string>()
                    {
                        "wwwww",
                    },
                dateTime = DateTime.Now
            };
            TestStorage<string> storage = new TestStorage<string>()
            {
                TestObjects = new List<TestObject<string>>()
                {
                    testObject1,
                    testObject2,
                    testObject3
                }.AsQueryable()
            };
            #endregion
            //Act
            var outputs = storage.TestObjects.ToList().StandardSearch<TestObject<string>>("Name", "Object1");
            var outputs2 = storage.TestObjects.ToList().StandardSearch<TestObject<string>>("SomeString", "String2");

            //Assert
            AssertTrue(outputs.Contains(testObject1));
            AssertTrue(outputs.Contains(testObject2));
            AssertFalse(outputs.Contains(testObject3));
            AssertTrue(outputs2.Contains(testObject1));
            AssertTrue(outputs2.Contains(testObject3));
            AssertFalse(outputs2.Contains(testObject2));
        }
 public void UsedSizeThrowsInvalidOperation()
 {
     TestStorage storage = new TestStorage();
     Assert.Throws<InvalidOperationException>(() => storage.UsedSize);
 }
 public void QuotaThrowsInvalidOperation()
 {
     TestStorage storage = new TestStorage();
     Assert.Throws<InvalidOperationException>(() => storage.Quota);
 }
 public void AvailableFreeSpaceThrowsInvalidOperation()
 {
     TestStorage storage = new TestStorage();
     Assert.Throws<InvalidOperationException>(() => storage.AvailableFreeSpace);
 }
 public void SeparatorInternalIsPeriod()
 {
     TestStorage storage = new TestStorage();
     Assert.Equal('.', storage.TestSeparatorInternal);
 }
 public void SeparatorExternalIsDirectorySeparator()
 {
     TestStorage storage = new TestStorage();
     Assert.Equal(Path.DirectorySeparatorChar, storage.TestSeparatorExternal);
 }
 public void IncreaseQuotaToReturnsFalse()
 {
     TestStorage storage = new TestStorage();
     Assert.False(storage.IncreaseQuotaTo(10));
 }
        public void TestFindExistingOutputs()
        {
            TestStorage storage = new TestStorage();
            storage.AddUnspentOutput(new UnspentOutput(0, Hash1, 1, 100, new byte[16]));

            UnspentOutputsUpdate update = new UnspentOutputsUpdate(storage);

            Assert.That(update.FindUnspentOutputs(Hash1).Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100}));
            Assert.That(update.FindUnspentOutputs(Hash2), Is.Empty);
        }
        public void TestFindExistingOutput()
        {
            TestStorage storage = new TestStorage();
            storage.AddUnspentOutput(new UnspentOutput(0, Hash1, 1, 100, new byte[16]));

            UnspentOutputsUpdate update = new UnspentOutputsUpdate(storage);

            Assert.That(update.FindUnspentOutput(Hash1, 0), Is.Null);
            Assert.That(update.FindUnspentOutput(Hash1, 1).Sum, Is.EqualTo(100));
            Assert.That(update.FindUnspentOutput(Hash2, 0), Is.Null);
            Assert.That(update.FindUnspentOutput(Hash2, 1), Is.Null);
        }
        public void TestOverwrite()
        {
            TestStorage storage = new TestStorage();
            storage.AddUnspentOutput(new UnspentOutput(0, Hash1, 0, 100, new byte[16]));
            storage.AddUnspentOutput(new UnspentOutput(0, Hash1, 1, 101, new byte[16]));

            UnspentOutputsUpdate update = new UnspentOutputsUpdate(storage);

            update.Spend(Hash1, 0, Block1);
            update.Spend(Hash1, 1, Block1);
            update.Add(new UnspentOutput(1, Hash1, 0, 200, new byte[16]));

            Assert.That(update.FindUnspentOutputs(Hash1).Select(o => o.Sum), Is.EqualTo(new ulong[] {200}));
            Assert.That(update.FindUnspentOutput(Hash1, 0).Sum, Is.EqualTo(200));
            Assert.That(update.FindUnspentOutput(Hash1, 1), Is.Null);

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100, 101}));
            Assert.That(storage.SpentOutputs, Is.Empty);

            update.Persist();

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {200}));
            Assert.That(storage.SpentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100, 101}));

            update = new UnspentOutputsUpdate(storage);

            update.Spend(Hash1, 0, Block2);
            update.Add(new UnspentOutput(2, Hash1, 0, 300, new byte[16]));
            update.Spend(Hash1, 0, Block2);
            update.Add(new UnspentOutput(2, Hash1, 0, 350, new byte[16]));

            Assert.That(update.FindUnspentOutputs(Hash1).Select(o => o.Sum), Is.EquivalentTo(new ulong[] {350}));
            Assert.That(update.FindUnspentOutput(Hash1, 0).Sum, Is.EqualTo(350));
            Assert.That(update.FindUnspentOutput(Hash1, 1), Is.Null);

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {200}));
            Assert.That(storage.SpentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100, 101}));

            update.Persist();

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {350}));
            Assert.That(storage.SpentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100, 101, 200}));
        }
        public void TestSpendNonExistent()
        {
            TestStorage storage = new TestStorage();
            storage.AddUnspentOutput(new UnspentOutput(0, Hash1, 0, 100, new byte[16]));

            UnspentOutputsUpdate update = new UnspentOutputsUpdate(storage);

            update.Spend(Hash1, 0, Block1);
            Assert.Throws<InvalidOperationException>(() => update.Spend(Hash1, 0, Block1));
            Assert.Throws<InvalidOperationException>(() => update.Spend(Hash1, 1, Block1));
            Assert.Throws<InvalidOperationException>(() => update.Spend(Hash2, 0, Block1));
            Assert.Throws<InvalidOperationException>(() => update.Spend(Hash2, 1, Block1));

            Assert.That(storage.UnspentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100}));
            Assert.That(storage.SpentOutputs, Is.Empty);

            update.Persist();

            Assert.That(storage.UnspentOutputs, Is.Empty);
            Assert.That(storage.SpentOutputs.Select(o => o.Sum), Is.EquivalentTo(new ulong[] {100}));
        }