public async Task LoadAllFromDeviceJournal() { Program.CleanProject(); var serializerService = Program.GetApp().Container.Resolve <ISerializerService>(); var device = serializerService.DeserializeFromFile <IDevice>("FileAssets/МР301_JA.json") as DefaultDevice; StaticContainer.Container.Resolve <IDevicesContainerService>() .AddConnectableItem(device); var shell = StaticContainer.Container.Resolve <ShellViewModel>(); var queryDefinitions = await QueryUtils.ReadQueryMockDefinitionFromFile("FileAssets/logFileForMR301JS.txt"); await StaticContainer.Container.Resolve <IDevicesContainerService>() .ConnectDeviceAsync(device, new MockConnectionWithSetup(queryDefinitions)); var journalViewModel = shell.ProjectBrowserViewModel.DeviceViewModels[0].FragmentViewModels .First(model => model.NameForUiKey == "UniconJournal(Журнал системы)") as UniconJournalViewModel; IDeviceViewModel deviceViewModel = shell.ProjectBrowserViewModel.DeviceViewModels[0]; var serializerServiceMock = new SerializerServiceMock(); var loadAllViewModel = new LoadAllFromDeviceWindowViewModelFactory(StaticContainer.Container.Resolve <ILoadAllService>(), serializerServiceMock) .CreateLoadAllFromDeviceWindowViewModel( device, deviceViewModel); Assert.True(loadAllViewModel.LoadFragmentViewModels.Count == 3); loadAllViewModel.PathToFolderToSave = Directory.GetCurrentDirectory(); loadAllViewModel.SaveToFolderCommand.Execute(null); await TestsUtils.WaitUntil(() => loadAllViewModel.SaveToFolderCommand.CanExecute(null)); Assert.True(serializerServiceMock.SerializedObjects.Count == 0); loadAllViewModel.LoadFragmentViewModels.First(model => model.FragmentName == "UniconJournal(Журнал системы)").IsSelectedForLoading = true; loadAllViewModel.SaveToFolderCommand.Execute(null); await TestsUtils.WaitUntil(() => loadAllViewModel.SaveToFolderCommand.CanExecute(null)); Assert.True(serializerServiceMock.SerializedObjects.Count == 1); Assert.True(((UniconJournal)serializerServiceMock.SerializedObjects[0]).JournalRecords.Count == 511); }
public async Task LoadAllFromDevice() { var setup = Program.RefreshProject(); var boolTestDefaultProperty = setup.configuration.RootConfigurationItemList .FindItemByName(item => item.Name == "boolTestDefaultProperty") .Item as IProperty; var connection = new MockConnection(); await StaticContainer.Container.Resolve <IDevicesContainerService>() .ConnectDeviceAsync(setup.device, connection); connection.MemorySlotDictionary.Add(boolTestDefaultProperty.Address, 1); var serializerService = new SerializerServiceMock(); var loadAllViewModel = new LoadAllFromDeviceWindowViewModelFactory(StaticContainer.Container.Resolve <ILoadAllService>(), serializerService) .CreateLoadAllFromDeviceWindowViewModel( setup.device, setup.deviceViewModel); Assert.True(loadAllViewModel.LoadFragmentViewModels.Count == 1); loadAllViewModel.PathToFolderToSave = Directory.GetCurrentDirectory(); loadAllViewModel.SaveToFolderCommand.Execute(null); await TestsUtils.WaitUntil(() => loadAllViewModel.SaveToFolderCommand.CanExecute(null)); Assert.True(serializerService.SerializedObjects.Count == 0); loadAllViewModel.LoadFragmentViewModels[0].IsSelectedForLoading = true; loadAllViewModel.SaveToFolderCommand.Execute(null); await TestsUtils.WaitUntil(() => loadAllViewModel.SaveToFolderCommand.CanExecute(null)); Assert.True(serializerService.SerializedObjects.Count == 1); var memorySaved = serializerService.SerializedObjects[0] as Dictionary <ushort, ushort>; Assert.True(memorySaved[boolTestDefaultProperty.Address] == 1); Assert.True(serializerService.SerializedObjects[0] is Dictionary <ushort, ushort>); connection.MemorySlotDictionary[boolTestDefaultProperty.Address] = 0; loadAllViewModel.SaveToFolderCommand.Execute(null); await TestsUtils.WaitUntil(() => loadAllViewModel.SaveToFolderCommand.CanExecute(null)); Assert.True(serializerService.SerializedObjects.Count == 2); var memorySaved1 = serializerService.SerializedObjects[1] as Dictionary <ushort, ushort>; Assert.True(memorySaved1[boolTestDefaultProperty.Address] == 0); await StaticContainer.Container.Resolve <IDevicesContainerService>() .ConnectDeviceAsync(setup.device, new OfflineConnection()); loadAllViewModel.SaveToFolderCommand.Execute(null); await TestsUtils.WaitUntil(() => loadAllViewModel.SaveToFolderCommand.CanExecute(null)); Assert.True(serializerService.SerializedObjects.Count == 2); }