public void TestUTF8Filenames(FileType fileType) { string filename = Path.GetTempPath() + "записано." + FileTypeService.GetFileExtension(fileType); IDataImportExport writeFile = FileTypeService.Create(filename, fileType); Assert.NotNull(writeFile, "IDataImportExport obj not created."); if (fileType == FileType.Matlab4) { ((IqMatlab)writeFile).MatlabFileVersion = MatlabVersion.Mat4; } else if (fileType == FileType.Matlab73) { ((IqMatlab)writeFile).MatlabFileVersion = MatlabVersion.Mat73; } IList <ChannelInfo> channelInfosWrite = new List <ChannelInfo>(); channelInfosWrite.Add(new ChannelInfo("Channel1", 12.2, 13.3)); IDictionary <string, string> metadataWrite = new Dictionary <string, string>(); metadataWrite.Add(new KeyValuePair <string, string>("Key1", "value 1")); metadataWrite.Add(new KeyValuePair <string, string>("Key2", "value 2")); IList <IList <double> > data = Common.InitDoubleVector(1, 6); try { writeFile.WriteOpen(IqDataFormat.Complex, 1, "application name", "my comment", channelInfosWrite, metadataWrite); writeFile.AppendChannels(data); writeFile.AppendChannels(data); writeFile.Close(); } catch (DaiException e) { Assert.Fail("Expected no exception, but got: " + e.Message); } bool fileExists = File.Exists(filename); Assert.IsTrue(fileExists, "File was not created"); File.Delete(filename); }
public async void Create() { var mock = new ServiceMockFacade <IFileTypeRepository>(); var model = new ApiFileTypeRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <FileType>())).Returns(Task.FromResult(new FileType())); var service = new FileTypeService(mock.LoggerMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FileTypeModelValidatorMock.Object, mock.BOLMapperMockFactory.BOLFileTypeMapperMock, mock.DALMapperMockFactory.DALFileTypeMapperMock, mock.BOLMapperMockFactory.BOLFileMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiFileTypeResponseModel> response = await service.Create(model); response.Should().NotBeNull(); mock.ModelValidatorMockFactory.FileTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFileTypeRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <FileType>())); }
public async void Create_NoErrorsOccurred_ShouldReturnResponse() { var mock = new ServiceMockFacade <IFileTypeService, IFileTypeRepository>(); var model = new ApiFileTypeServerRequestModel(); mock.RepositoryMock.Setup(x => x.Create(It.IsAny <FileType>())).Returns(Task.FromResult(new FileType())); var service = new FileTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, mock.ModelValidatorMockFactory.FileTypeModelValidatorMock.Object, mock.DALMapperMockFactory.DALFileTypeMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiFileTypeServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeTrue(); mock.ModelValidatorMockFactory.FileTypeModelValidatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFileTypeServerRequestModel>())); mock.RepositoryMock.Verify(x => x.Create(It.IsAny <FileType>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FileTypeCreatedNotification>(), It.IsAny <CancellationToken>())); }
public async void Create_ErrorsOccurred_ShouldReturnErrorResponse() { var mock = new ServiceMockFacade <IFileTypeService, IFileTypeRepository>(); var model = new ApiFileTypeServerRequestModel(); var validatorMock = new Mock <IApiFileTypeServerRequestModelValidator>(); validatorMock.Setup(x => x.ValidateCreateAsync(It.IsAny <ApiFileTypeServerRequestModel>())).Returns(Task.FromResult(new FluentValidation.Results.ValidationResult(new List <ValidationFailure>() { new ValidationFailure("text", "test") }))); var service = new FileTypeService(mock.LoggerMock.Object, mock.MediatorMock.Object, mock.RepositoryMock.Object, validatorMock.Object, mock.DALMapperMockFactory.DALFileTypeMapperMock, mock.DALMapperMockFactory.DALFileMapperMock); CreateResponse <ApiFileTypeServerResponseModel> response = await service.Create(model); response.Should().NotBeNull(); response.Success.Should().BeFalse(); validatorMock.Verify(x => x.ValidateCreateAsync(It.IsAny <ApiFileTypeServerRequestModel>())); mock.MediatorMock.Verify(x => x.Publish(It.IsAny <FileTypeCreatedNotification>(), It.IsAny <CancellationToken>()), Times.Never()); }
public void TestFactoryArrays(FileType fileType) { string filename = Path.GetTempPath() + "TestFactoryArrays." + FileTypeService.GetFileExtension(fileType); IDataImportExport writeFile = FileTypeService.Create(filename, fileType); Assert.NotNull(writeFile, "IDataImportExport obj not created."); if (fileType == FileType.Matlab4) { ((IqMatlab)writeFile).MatlabFileVersion = MatlabVersion.Mat4; } else if (fileType == FileType.Matlab73) { ((IqMatlab)writeFile).MatlabFileVersion = MatlabVersion.Mat73; } IList <ChannelInfo> channelInfosWrite = new List <ChannelInfo>(); channelInfosWrite.Add(new ChannelInfo("Channel1", 12.2, 13.3)); IDictionary <string, string> metadataWrite = new Dictionary <string, string>(); metadataWrite.Add(new KeyValuePair <string, string>("Key1", "value 1")); metadataWrite.Add(new KeyValuePair <string, string>("Key2", "value 2")); IList <IList <double> > data = Common.InitDoubleVector(2, 5); try { writeFile.WriteOpen(IqDataFormat.Complex, 2, "application name", "my comment", channelInfosWrite, metadataWrite); writeFile.AppendArrays(data); writeFile.AppendArrays(data); writeFile.Close(); } catch (DaiException e) { Assert.Fail("Expected no exception, but got: " + e.Message); } IDataImportExport readFile = FileTypeService.Create(filename, fileType); Assert.NotNull(readFile, "IDataImportExport obj not created."); try { IList <string> arrayNames = readFile.ReadOpen(); Assert.AreEqual(arrayNames.Count, 2, "invalid array count"); Assert.AreEqual("Channel1_I", arrayNames[0], "invalid array name"); Assert.AreEqual("Channel1_Q", arrayNames[1], "invalid array name"); Assert.AreEqual(readFile.ChannelInformation.Count, channelInfosWrite.Count, "number of found channels incorrect"); Assert.AreEqual(readFile.ChannelInformation[0].ChannelName, channelInfosWrite[0].ChannelName); if (fileType != FileType.IQW) { Assert.AreEqual(readFile.ChannelInformation[0].ClockRate, channelInfosWrite[0].ClockRate); Assert.AreEqual(readFile.ChannelInformation[0].Frequency, channelInfosWrite[0].Frequency); IDictionary <string, string> readMetadata = readFile.Metadata; foreach (var kvp in metadataWrite) { bool containsKey = readMetadata.ContainsKey(kvp.Key); Assert.True(containsKey, "metadata key not found"); string value = readMetadata[kvp.Key]; Assert.AreEqual(value, kvp.Value, "metadata value mismatch"); } } int arrayLen = (int)readFile.GetArraySize(arrayNames[0]); IList <double> ivalues = new List <double>(arrayLen); IList <double> qvalues = new List <double>(arrayLen); readFile.ReadArray(arrayNames[0], ref ivalues, arrayLen); readFile.ReadArray(arrayNames[1], ref qvalues, arrayLen); for (int i = 0; i < arrayLen / 2; ++i) { Assert.AreEqual(data[0][i], ivalues[i]); Assert.AreEqual(data[1][i], qvalues[i]); } for (int i = arrayLen / 2; i < arrayLen; ++i) { Assert.AreEqual(data[0][i - arrayLen / 2], ivalues[i]); Assert.AreEqual(data[1][i - arrayLen / 2], qvalues[i]); } readFile.Close(); } catch (DaiException e) { Assert.Fail("Expected no exception, but got: " + e.Message); } File.Delete(filename); }