public void PropertyFilter() { var schedulerProvider = new TestSchedulerProvider(); using (var sourceList = new SourceList <Animal>()) using (var sut = new PropertyFilter(sourceList, schedulerProvider)) { //start the scheduler schedulerProvider.TestScheduler.Start(); //add items sourceList.AddRange(_items); sut.Filtered.Count.Should().Be(0); //set to true to include in the result set _items[1].IncludeInResults = true; _items[2].IncludeInResults = true; _items[3].IncludeInResults = true; //progress scheduler schedulerProvider.TestScheduler.Start(); sut.Filtered.Items.ShouldAllBeEquivalentTo(new [] { _items[1], _items[2], _items[3] }); } }
public void DynamicFilter() { var schedulerProvider = new TestSchedulerProvider(); using (var sourceList = new SourceList <Animal>()) using (var sut = new DynamicFilter(sourceList, schedulerProvider)) { //start the scheduler schedulerProvider.TestScheduler.Start(); //add items sourceList.AddRange(_items); sut.Filtered.Items.ShouldAllBeEquivalentTo(_items); sut.Filtered.Count.Should().Be(_items.Length); //set a filter sut.AnimalFilter = "Dog"; schedulerProvider.TestScheduler.Start(); sut.Filtered.Items.ShouldAllBeEquivalentTo(_items.Where(a => a.Type == "Dog")); sut.Filtered.Count.Should().Be(2); //add a new dog to show it is included in the result set sourceList.Add(new Animal("George", "Dog", AnimalFamily.Mammal)); sut.Filtered.Count.Should().Be(3); //add a new bird to show it is included in the result set sourceList.Add(new Animal("Peter", "Parrot", AnimalFamily.Bird)); sut.Filtered.Count.Should().Be(3); } }
public virtual void SetUp() { _bluetoothServiceMock = new Mock <IBluetoothService>(); _bluetoothServiceMock.Setup(bs => bs.IsSupported).Returns(true); _bluetoothServiceMock.SetupAllProperties(); _bluetoothProfileActivator = new Mock <IBluetoothProfileActivator>(); _bluetoothProfileActivator.SetupAllProperties(); _bluetoothProfileActivator.Object.IsEnabled = true; _testSchedulerProvider = new TestSchedulerProvider(); _viewModel = new BluetoothSetupViewModel(_bluetoothServiceMock.Object, _bluetoothProfileActivator.Object, _testSchedulerProvider); }
public ImageManagementServiceTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper) { _autoSubstitute = new AutoSubstitute(); _testSchedulerProvider = new TestSchedulerProvider(); _autoSubstitute.Provide <ISchedulerProvider>(_testSchedulerProvider); _unitOfWorkQueue = new Queue <IUnitOfWork>(); _autoSubstitute.Provide <Func <IUnitOfWork> >(() => _unitOfWorkQueue.Dequeue()); _mockFileSystem = new MockFileSystem(); _autoSubstitute.Provide <IFileSystem>(_mockFileSystem); }
public virtual void Setup() { _bluetoothServiceMock = new Mock <IBluetoothService>(); _testSchedulerProvider = new TestSchedulerProvider(); _bluetoothDeviceInfoMock = new Mock <IBluetoothDeviceInfo>(); _sut = new BluetoothDevice(_bluetoothDeviceInfoMock.Object, _bluetoothServiceMock.Object, _testSchedulerProvider); _bluetoothDeviceInfoMock.Setup(bt => bt.DeviceAddress).Returns(_expectedAddress); _bluetoothDeviceInfoMock.Setup(bt => bt.DeviceName).Returns(_expectedName); _bluetoothDeviceInfoMock.Setup(bt => bt.DeviceType).Returns(BluetoothDeviceType.Create(DeviceClass.SmartPhone)); }
public void CanGetImages() { Logger.Debug("CanGetImages"); var directory = Faker.System.DirectoryPathWindows(); var subDirectory = Path.Combine(directory, Faker.Random.Word()); var mockFileSystem = new MockFileSystem(); _autoSub.Provide <IFileSystem>(mockFileSystem); var files = new[] { "jpg", "jpeg", "png", "tiff", "tif", "bmp" } .Select(ext => Path.Combine(subDirectory, Faker.System.FileName(ext))) .ToArray(); var otherFiles = new[] { "txt", "doc" } .Select(ext => Path.Combine(subDirectory, Faker.System.FileName(ext))) .ToArray(); foreach (var file in files.Concat(otherFiles)) { mockFileSystem.AddFile(file, new MockFileData(new byte[0])); } var autoResetEvent = new AutoResetEvent(false); string[] imagePaths = null; var testSchedulerProvider = new TestSchedulerProvider(); _autoSub.Provide <ISchedulerProvider>(testSchedulerProvider); var imageLocationService = _autoSub.Resolve <ImageLocationService>(); imageLocationService.GetImages(directory) .Subscribe(paths => { imagePaths = paths; autoResetEvent.Set(); }); testSchedulerProvider.TaskPool.AdvanceBy(1); autoResetEvent.WaitOne(); imagePaths.Should().NotBeNull(); imagePaths.Select(fileInfo => fileInfo) .Should().BeEquivalentTo(files); }
public void SelectedItemsTests() { var schedulerProvider = new TestSchedulerProvider(); var items = Enumerable.Range(1, 10).Select(i => new CacheItem(i.ToString())).ToArray(); using (var sut = new SelectCacheItem(schedulerProvider)) { sut.Load(items); sut.SelectedItem.Id.Should().Be("1"); sut.AddOrUpdate(new CacheItem("11")); sut.SelectedItem.Id.Should().Be("11"); } }
public void XamarinFormsGrouping() { var items = new[] { new Animal("Holly", "Cat", AnimalFamily.Mammal), new Animal("Rover", "Dog", AnimalFamily.Mammal), new Animal("Rex", "Dog", AnimalFamily.Mammal), new Animal("Whiskers", "Cat", AnimalFamily.Mammal), new Animal("Nemo", "Fish", AnimalFamily.Fish), new Animal("Moby Dick", "Whale", AnimalFamily.Mammal), new Animal("Fred", "Frog", AnimalFamily.Amphibian), new Animal("Isaac", "Next", AnimalFamily.Amphibian), new Animal("Sam", "Snake", AnimalFamily.Reptile), new Animal("Sharon", "Red Backed Shrike", AnimalFamily.Bird), }; var schedulerProvider = new TestSchedulerProvider(); using (var sourceList = new SourceList <Animal>()) using (var sut = new XamarinFormsGrouping(sourceList, schedulerProvider)) { //populate with initial data sourceList.AddRange(items); schedulerProvider.TestScheduler.Start(); sut.FamilyGroups.Count.Should().Be(5); sut.FamilyGroups.Single(group => group.Family == AnimalFamily.Mammal).Count.Should().Be(5); sut.FamilyGroups.Single(group => group.Family == AnimalFamily.Fish).Count.Should().Be(1); //apply a filter sut.Filter = a => a.Type == "Dog" || a.Type == "Fish"; schedulerProvider.TestScheduler.Start(); sut.FamilyGroups.Count.Should().Be(2); sut.FamilyGroups.Single(group => group.Family == AnimalFamily.Mammal).Count.Should().Be(2); sut.FamilyGroups.Single(group => group.Family == AnimalFamily.Fish).Count.Should().Be(1); //clear list and all groupings are gone sourceList.Clear(); schedulerProvider.TestScheduler.Start(); sut.FamilyGroups.Count.Should().Be(0); } }
public void IsPaused() { var schedulerProvider = new TestSchedulerProvider(); using (var testData = new DataProviderStub()) using (var sut = new ViewModel(testData, schedulerProvider)) { sut.IsPaused = true; schedulerProvider.TestScheduler.Start(); //push scheduler forward //add data after pause has started testData.Data.AddOrUpdate(Enumerable.Range(1, 10).Select(i => new Item(i))); schedulerProvider.TestScheduler.AdvanceBy(1); //check no data has been pipelined sut.BindingData.Count.Should().Be(0); //turn pause off and check the updates have been pushed through sut.IsPaused = false; schedulerProvider.TestScheduler.AdvanceBy(1); sut.BindingData.Count.Should().Be(10); } }
public void Binding() { var schedulerProvider = new TestSchedulerProvider(); using (var testData = new DataProviderStub()) using (var sut = new ViewModel(testData, schedulerProvider)) { //Act var items = Enumerable.Range(1, 10).Select(i => new Item(i)).ToArray(); testData.Data.AddOrUpdate(items); schedulerProvider.TestScheduler.Start(); //push scheduler forward //1. Check count of data sut.BindingData.Count.Should().Be(10); //2. Check Transform and Sort var expectedData = items .Select(i => new ItemViewModel(i)) .OrderByDescending(vm => vm.Item.Id); sut.BindingData.ShouldAllBeEquivalentTo(expectedData); } }
public void CanLoadImage() { Logger.Debug("CanLoadImage"); using (var autoSub = new AutoSubstitute()) { var mockFileSystem = new MockFileSystem(); autoSub.Provide <IFileSystem>(mockFileSystem); var resourceAssembly = Assembly.GetAssembly(typeof(ImageLoadingServiceTests)); var filePath = Path.Combine(Faker.System.DirectoryPathWindows(), Faker.System.FileName("jpg")); mockFileSystem.AddFileFromEmbeddedResource(filePath, resourceAssembly, "SonOfPicasso.UI.Tests.Resources.DSC04085.JPG"); var autoResetEvent = new AutoResetEvent(false); IBitmap bitmap = null; var testSchedulerProvider = new TestSchedulerProvider(); autoSub.Provide <ISchedulerProvider>(testSchedulerProvider); var imageLoadingService = autoSub.Resolve <ImageLoadingService>(); imageLoadingService.LoadImageFromPath(filePath).Subscribe(b => { bitmap = b; autoResetEvent.Set(); }); testSchedulerProvider.TaskPool.AdvanceBy(1); autoResetEvent.WaitOne(); bitmap.Should().NotBeNull(); bitmap.Height.Should().BeApproximately(1000.6f, 0.01f); bitmap.Width.Should().BeApproximately(1334.12f, 0.01f); } }