public async Task WHEN_Cart_has_no_valid_fulfillmentLocationId_SHOULD_invoke_UpdateShipment() { //Arrange _container.Use(OvertureClientFactory.Create()); var sut = _container.CreateInstance <FixCartService>(); //Act await sut.FixCartAsync(new FixCartParam { Cart = new ProcessedCart { CultureName = "en-US", Payments = new List <Payment> { new Payment() }, Shipments = new List <Shipment> { new Shipment() } } }); //Assert _container.Verify <ICartRepository>(r => r.UpdateShipmentAsync(It.IsNotNull <UpdateShipmentParam>())); }
public async Task TestCopyOperation(bool throws, OperationState state) { var copySetup = _autoMocker .Setup <IFileService, Task <bool> >(m => m.CopyAsync(SourceName, DestinationName, false)) .ReturnsAsync(!throws); copySetup.Verifiable(); var operationsFactory = _autoMocker.CreateInstance <OperationsFactory>(); var settings = new BinaryFileSystemOperationSettings( new string[] { }, new[] { SourceName }, new string[] { }, new[] { SourceName }, new Dictionary <string, string> { [SourceName] = DestinationName }, new string[] { } ); var copyOperation = operationsFactory.CreateCopyOperation(settings); Assert.Equal(OperationState.NotStarted, copyOperation.State); var isCallbackCalled = false; copyOperation.StateChanged += (sender, args) => isCallbackCalled = true; await copyOperation.RunAsync(); Assert.Equal(state, copyOperation.State); Assert.True(isCallbackCalled); _autoMocker.Verify <IFileService>(m => m.CopyAsync(SourceName, DestinationName, false), Times.Once); }
public void TestActivation() { var themes = new[] { new ThemeViewModel(Theme.Dark, "Dark"), new ThemeViewModel(Theme.Light, "Light") }; _autoMocker .Setup <IThemeViewModelFactory, IReadOnlyList <ThemeViewModel> >(m => m.CreateAll()) .Returns(themes) .Verifiable(); _autoMocker .Setup <IThemeService, Theme>(m => m.GetCurrentTheme()) .Returns(Theme.Light); var viewModel = _autoMocker.CreateInstance <ThemeSettingsViewModel>(); for (var i = 0; i < 10; i++) { viewModel.Activate(); } Assert.Equal(themes.Last(), viewModel.CurrentTheme); Assert.False(viewModel.IsChanged); Assert.Equal(2, viewModel.Themes.Count()); Assert.Equal(themes.First(), viewModel.Themes.First()); Assert.Equal(themes.Last(), viewModel.Themes.Last()); _autoMocker .Verify <IThemeViewModelFactory, IReadOnlyList <ThemeViewModel> >(m => m.CreateAll(), Times.Once); }
public void TestEmptyFilesPanelState() { var tabViewModelMock = new Mock <ITabViewModel>(); tabViewModelMock .SetupGet(m => m.SortingViewModel) .Returns(Mock.Of <IFileSystemNodesSortingViewModel>()); var tabViewModel = tabViewModelMock.Object; _autoMocker .Setup <ITabViewModelFactory, ITabViewModel>(m => m.Create(It.IsAny <IFilePanelDirectoryObserver>(), It.IsAny <TabStateModel>())) .Returns(tabViewModel); _autoMocker .Setup <IFilesPanelStateService, PanelStateModel>(m => m.GetPanelState()) .Returns(new PanelStateModel() { Tabs = new List <TabStateModel>() }) .Verifiable(); _autoMocker .Setup <IHomeDirectoryProvider, string>(m => m.HomeDirectoryPath) .Returns(AppRootDirectory) .Verifiable(); _autoMocker .Setup <IDirectoryService, bool>(m => m.CheckIfExists(AppRootDirectory)) .Returns(true); var tabsListViewModel = _autoMocker.CreateInstance <TabsListViewModel>(); _autoMocker.Verify <IFilesPanelStateService, PanelStateModel>(m => m.GetPanelState(), Times.Once); _autoMocker.Verify <IHomeDirectoryProvider, string>(m => m.HomeDirectoryPath, Times.Once); Assert.Single(tabsListViewModel.Tabs); Assert.Equal(tabViewModel, tabsListViewModel.SelectedTab); }
public void VerifyJsonGetsSavedInClipboard() { var mocker = new AutoMocker(); var userData = new List <AudioDramaUserData> { new AudioDramaUserData(Guid.Empty, true, false), new AudioDramaUserData(Guid.Empty, false, true), }; mocker .GetMock <ICache <IEnumerable <AudioDramaUserData> > >() .Setup(x => x.Load()) .Returns(userData); var sut = mocker.CreateInstance <UserDataImportExport>(); sut.ExportUserData(); mocker.Verify <ICache <IEnumerable <AudioDramaUserData> > >(x => x.Load(), Times.Once); mocker.Verify <IYesNoDialog>(x => x.Show(It.IsAny <string>(), It.Is <string>(y => y.Contains(": 2") && y.Contains(": 1")))); mocker.GetMock <IYesNoDialog>().Raise(x => x.YesClicked += null, this, EventArgs.Empty); var json = JsonConvert.SerializeObject(userData); mocker.Verify <IClipboardService>(x => x.SetClipboardText(json), Times.Once); }
public async Task TestGetInstalledApplicationsAsyncMultiple() { _autoMocker .Setup <IFileService, IReadOnlyList <FileModel> >(m => m.GetFiles(It.IsAny <string>(), It.IsAny <ISpecification <FileModel> >())) .Returns(new FileModel[0]) .Verifiable(); _autoMocker .Setup <IFileService, IReadOnlyList <FileModel> >(m => m.GetFiles(It.IsAny <IReadOnlyList <string> >())) .Returns(new FileModel[0]) .Verifiable(); _autoMocker .Setup <IIniReader, Task <IReadOnlyDictionary <string, string> > >(m => m.ReadAsync(It.IsAny <Stream>())) .ReturnsAsync(new Dictionary <string, string>()); var service = _autoMocker.CreateInstance <LinuxApplicationService>(); for (var i = 0; i < 10; i++) { await service.GetInstalledApplicationsAsync(); } _autoMocker .Verify <IFileService>(m => m.GetFiles(It.IsAny <string>(), It.IsAny <ISpecification <FileModel> >()), Times.Once); _autoMocker .Verify <IFileService>(m => m.GetFiles(It.IsAny <IReadOnlyList <string> >()), Times.Once); }
public void TestEmptyFilesPanelState() { var tabViewModel = new Mock <ITabViewModel>().Object; _autoMocker .Setup <ITabViewModelFactory, ITabViewModel>(m => m.Create(It.IsAny <TabModel>())) .Returns(tabViewModel); _autoMocker .Setup <IFilesPanelStateService, PanelModel>(m => m.GetPanelState()) .Returns(PanelModel.Empty) .Verifiable(); _autoMocker .Setup <IDirectoryService, string>(m => m.GetAppRootDirectory()) .Returns(AppRootDirectory) .Verifiable(); _autoMocker .Setup <IDirectoryService, bool>(m => m.CheckIfExists(AppRootDirectory)) .Returns(true); var tabsListViewModel = _autoMocker.CreateInstance <TabsListViewModel>(); _autoMocker.Verify <IFilesPanelStateService, PanelModel>(m => m.GetPanelState(), Times.Once); _autoMocker.Verify <IDirectoryService, string>(m => m.GetAppRootDirectory(), Times.Once); Assert.Single(tabsListViewModel.Tabs); Assert.Equal(tabViewModel, tabsListViewModel.SelectedTab); }
public async Task SyncsMovieWithGuidFromInitalMetadata() { var content = new Mediacontainer { Metadata = new[] { new Metadata { title = "test1", year = 2021, type = "movie", Guid = new List <PlexGuids> { new PlexGuids { Id = "imdb://tt0322259" } }, ratingKey = "1" }, } }; var contentToAdd = new HashSet <PlexServerContent>(); var contentProcessed = new Dictionary <int, string>(); await _subject.MovieLoop(new PlexServers(), content, contentToAdd, contentProcessed); var first = contentToAdd.First(); Assert.That(first.ImdbId, Is.EqualTo("tt0322259")); _mocker.Verify <IPlexApi>(x => x.GetMetadata(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()), Times.Never); }
public void TestActivation() { var fileModel = new FileModel { FullPath = File, SizeBytes = Size }; _autoMocker .Setup <IFileService, FileModel>(m => m.GetFile(File)) .Returns(fileModel); _autoMocker .Setup <IMainNodeInfoTabViewModel>(m => m.SetSize(Size)) .Verifiable(); _autoMocker .Setup <IMainNodeInfoTabViewModel>(m => m.Activate(fileModel, false, 0, 0)) .Verifiable(); var viewModel = _autoMocker.CreateInstance <FileInformationDialogViewModel>(); var parameter = new FileSystemNodeNavigationParameter(File); viewModel.Activate(parameter); _autoMocker .Verify <IMainNodeInfoTabViewModel>(m => m.SetSize(Size), Times.Once); _autoMocker .Verify <IMainNodeInfoTabViewModel>(m => m.Activate(fileModel, false, 0, 0), Times.Once); }
public void AudioDramaClicked_OpenAudioDramaView() { _mocker .GetMock <IAudioDramaListView>() .Raise(x => x.AudioDramaClicked += null, this, _audioDramas.First().AudioDramaDto.Id); _mocker.Verify <IRootView>(x => x.Show(It.IsAny <IAudioDramaView>()), Times.Once); }
public void You_can_verify_a_single_method_call_directly() { var mock = new Mock <IService2>(); mocker.Use(mock); var name = mock.Object.Name; mocker.Verify <IService2>(x => x.Name); }
public void TestOpenNoSelectedApp() { var service = _autoMocker.CreateInstance <ResourceOpeningServiceOpenWith>(); service.Open(Resource); _autoMocker .Verify <IResourceOpeningService>(m => m.Open(Resource), Times.Once); }
public async Task ProcessRequestAsync_Ignore_Secret(string commandText, TrayCommandType command) { // Arrange _mocker.GetMock <ITrayCommandHelper>().Setup(x => x.GetCommandType(commandText)).Returns(command); // Act await _hostHelper.ProcessRequestAsync($"/someCode/{commandText}").ConfigureAwait(false); // Assert _mocker.Verify <ITrayCommandHelper>(x => x.RunCommand(command), Times.Once); }
public void TestRefreshCommand() { _autoMocker .Setup <IDirectoryService, bool>(m => m.CheckIfExists(AppRootDirectory)) .Returns(true); _autoMocker .Setup <IDirectoryService, IReadOnlyList <DirectoryModel> >(m => m.GetChildDirectories(AppRootDirectory, It.IsAny <ISpecification <DirectoryModel> >())) .Returns(new DirectoryModel[] {}) .Verifiable(); _autoMocker .Setup <IFileService, IReadOnlyList <FileModel> >(m => m.GetFiles(AppRootDirectory, It.IsAny <ISpecification <NodeModelBase> >())) .Returns(new FileModel[] {}) .Verifiable(); var tabViewModelMock = new Mock <ITabViewModel>(); tabViewModelMock .SetupGet(m => m.CurrentDirectory) .Returns(AppRootDirectory); var tabsListViewModelMock = new Mock <ITabsListViewModel>(); tabsListViewModelMock .SetupGet(m => m.SelectedTab) .Returns(tabViewModelMock.Object); _autoMocker.Use(tabsListViewModelMock.Object); var filesPanelViewModel = _autoMocker.CreateInstance <FilesPanelViewModel>(); _autoMocker .Verify <IDirectoryService, IReadOnlyList <DirectoryModel> >( m => m.GetChildDirectories(AppRootDirectory, It.IsAny <ISpecification <DirectoryModel> >()), Times.Once); _autoMocker .Verify <IFileService, IReadOnlyList <FileModel> >( m => m.GetFiles(AppRootDirectory, It.IsAny <ISpecification <NodeModelBase> >()), Times.Once); var random = new Random(); var refreshCount = random.Next(5, 15); for (var i = 0; i < refreshCount; i++) { Assert.True(filesPanelViewModel.RefreshCommand.CanExecute(null)); filesPanelViewModel.RefreshCommand.Execute(null); } _autoMocker .Verify <IDirectoryService, IReadOnlyList <DirectoryModel> >( m => m.GetChildDirectories(AppRootDirectory, It.IsAny <ISpecification <DirectoryModel> >()), Times.Exactly(refreshCount + 1)); _autoMocker .Verify <IFileService, IReadOnlyList <FileModel> >( m => m.GetFiles(AppRootDirectory, It.IsAny <ISpecification <NodeModelBase> >()), Times.Exactly(refreshCount + 1)); }
public void TestDirectoryCreationSuccess() { _autoMocker .Setup <IEnvironmentDirectoryService>(m => m.CreateDirectory(DirectoryName)) .Verifiable(); var directoryService = _autoMocker.CreateInstance <DirectoryService>(); var result = directoryService.Create(DirectoryName); Assert.True(result); _autoMocker .Verify <IEnvironmentDirectoryService>(m => m.CreateDirectory(DirectoryName)); }
public void TestFileOpeningMacOs(string fileName, string command, string arguments) { _autoMocker .Setup <IProcessService>(m => m.Run(command, arguments)) .Verifiable(); var fileOpeningService = _autoMocker.CreateInstance <MacResourceOpeningService>(); fileOpeningService.Open(fileName); _autoMocker .Verify <IProcessService>(m => m.Run(command, arguments), Times.Once); }
public async Task TestPackAsync(ArchiveType archiveType) { var nodes = new[] { FilePath }; _autoMocker .Setup <IOperationsService>(m => m.PackAsync(nodes, OutputFilePath, archiveType)) .Verifiable(); var service = _autoMocker.CreateInstance <ArchiveService>(); await service.PackAsync(nodes, OutputFilePath, archiveType); _autoMocker .Verify <IOperationsService>(m => m.PackAsync(nodes, OutputFilePath, archiveType), Times.Once); }
public void TestFileOpening() { _autoMocker .Setup <IResourceOpeningService>(m => m.Open(FileName)) .Verifiable(); var fileOpeningBehavior = _autoMocker.CreateInstance <FileOpeningBehavior>(); fileOpeningBehavior.Open(FileName); _autoMocker .Verify <IResourceOpeningService>(m => m.Open(FileName), Times.Once); }
public void OnGetView_Update_SelectedTab_SelectedFilter_SelectedSortMode() { var view = _mocker.GetMock <IAudioDramaView>(); view.Raise(x => x.BackClicked += null, this, EventArgs.Empty); _mocker.Verify <IAudioDramaListView>(x => x.SetSelectedInterpreter(It.IsAny <EAudioDramaFilterMode>()), Times.Once); _mocker.Verify <IAudioDramaListView>(x => x.SetFilterInfos(It.IsAny <EAudioDramaFilterMode>()), Times.Once); _mocker.Verify <IAudioDramaListView>(x => x.SetSelectedSortMode(It.IsAny <EAudioDramaSortMode>()), Times.Once); }
public async Task TestActivation() { var taskCompletionSource = new TaskCompletionSource <bool>(); var directoryModel = new DirectoryModel { FullPath = Directory }; _autoMocker .Setup <IDirectoryService, DirectoryModel>(m => m.GetDirectory(Directory)) .Returns(directoryModel); _autoMocker .Setup <IDirectoryService, long>(m => m.CalculateSize(Directory)) .Returns(Size); _autoMocker .Setup <IApplicationDispatcher>(m => m.Dispatch(It.IsAny <Action>())) .Callback <Action>(action => { action(); taskCompletionSource.SetResult(true); }); _autoMocker .Setup <IDirectoryService, IReadOnlyList <DirectoryModel> >(m => m.GetChildDirectories(Directory, null)) .Returns(Enumerable.Repeat(new DirectoryModel(), DirsCount).ToArray()); _autoMocker .Setup <IFileService, IReadOnlyList <FileModel> >(m => m.GetFiles(Directory, null)) .Returns(Enumerable.Repeat(new FileModel(), FilesCount).ToArray()); _autoMocker .Setup <IMainNodeInfoTabViewModel>(m => m.SetSize(Size)) .Verifiable(); _autoMocker .Setup <IMainNodeInfoTabViewModel>(m => m.Activate(directoryModel, true, FilesCount, DirsCount)) .Verifiable(); var viewModel = _autoMocker.CreateInstance <DirectoryInformationDialogViewModel>(); var parameter = new FileSystemNodeNavigationParameter(Directory); viewModel.Activate(parameter); await Task.WhenAny(taskCompletionSource.Task, Task.Delay(1000)); _autoMocker .Verify <IMainNodeInfoTabViewModel>(m => m.SetSize(Size), Times.Once); _autoMocker .Verify <IMainNodeInfoTabViewModel>(m => m.Activate(directoryModel, true, FilesCount, DirsCount), Times.Once); }
public void TestDirectoryUpdated() { var currentDirectory = AppRootDirectory; var tabViewModelMock = new Mock <ITabViewModel>(); tabViewModelMock .SetupGet(m => m.CurrentDirectory) .Returns(() => currentDirectory); tabViewModelMock .SetupSet(m => m.CurrentDirectory = NewDirectory) .Callback <string>(s => currentDirectory = s); _autoMocker .Setup <ITabsListViewModel, ITabViewModel>(m => m.SelectedTab) .Returns(tabViewModelMock.Object); _autoMocker .Setup <IDirectoryService, bool>(m => m.CheckIfExists(NewDirectory)) .Returns(true); _autoMocker .Setup <IDirectoryService, IReadOnlyList <DirectoryModel> >(m => m.GetChildDirectories(It.IsAny <string>(), It.IsAny <ISpecification <DirectoryModel> >())) .Returns(new DirectoryModel[] {}); _autoMocker .Setup <IFileService, IReadOnlyList <FileModel> >(m => m.GetFiles(NewDirectory, It.IsAny <ISpecification <NodeModelBase> >())) .Returns(new[] { new FileModel { Name = File } }); _autoMocker .Setup <ISearchViewModel, INodeSpecification>(m => m.GetSpecification()) .Returns(new Mock <INodeSpecification>().Object); _autoMocker .Setup <IFilePanelDirectoryObserver, string>(m => m.CurrentDirectory) .Returns(NewDirectory); var filesPanelViewModel = _autoMocker.CreateInstance <FilesPanelViewModel>(); _autoMocker .Verify <IDirectoryService, DirectoryModel>(m => m.GetParentDirectory(NewDirectory), Times.Exactly(3)); _autoMocker .GetMock <IFilePanelDirectoryObserver>() .Raise(m => m.CurrentDirectoryChanged += null, EventArgs.Empty); Assert.Single(filesPanelViewModel.FileSystemNodes); Assert.Equal(NewDirectory, filesPanelViewModel.CurrentDirectory); _autoMocker .Verify <IDirectoryService, DirectoryModel>(m => m.GetParentDirectory(NewDirectory), Times.Exactly(6)); }
public void TestOpening(DesktopEnvironment desktopEnvironment, string command) { var args = $@"--workdir \""{Directory}\"""; var uowMock = new Mock <IUnitOfWork>(); uowMock .Setup(m => m.GetRepository <TerminalSettings>()) .Returns(new Mock <IRepository <TerminalSettings> >().Object); _autoMocker .Setup <IUnitOfWorkFactory, IUnitOfWork>(m => m.Create()) .Returns(uowMock.Object); _autoMocker .Setup <IProcessService>(m => m.Run(command, args)) .Verifiable(); _autoMocker .Setup <IDesktopEnvironmentService, DesktopEnvironment>(m => m.GetDesktopEnvironment()) .Returns(desktopEnvironment); _autoMocker .Setup <IShellCommandWrappingService, (string, string)>(m => m.WrapWithNohup(It.IsAny <string>(), It.IsAny <string>())) .Returns <string, string>((c, a) => (c, a)); var terminalService = _autoMocker.CreateInstance <LinuxTerminalService>(); terminalService.Open(Directory); _autoMocker.Verify <IProcessService>(m => m.Run(command, args), Times.Once); }
public async Task WHEN_param_is_ok_SHOULD_fill_criteria_context_from_ComposerContext() { //Arrange var scope = GetRandom.String(6); var cultureInfo = CultureInfo.InvariantCulture; ArrangeComposerContext(scope, cultureInfo); var param = CreateEmptyParam(); GetCategoryBrowsingViewModelParam passedParam = null; var sut = _container.CreateInstance <BrowseCategoryRequestContext>(); var catBrowsingMock = _container.GetMock <ICategoryBrowsingViewService>(); catBrowsingMock .Setup(q => q.GetCategoryBrowsingViewModelAsync(It.IsAny <GetCategoryBrowsingViewModelParam>())) .Callback((GetCategoryBrowsingViewModelParam p) => passedParam = p) .ReturnsAsync(new CategoryBrowsingViewModel()); //Act await sut.GetCategoryAvailableProductsAsync(param); //Assert passedParam.CultureInfo.Should().NotBeNull(); passedParam.CultureInfo.Should().Be(cultureInfo); _container.Verify <IComposerContext>(); }
public async Task TestMoveToTrash(string volume, string newFilePath, string[] existingFiles) { _autoMocker .Setup <IMountedDriveService, DriveModel>(m => m.GetFileDrive(It.IsAny <string>())) .Returns(new DriveModel { RootDirectory = volume }); _autoMocker .Setup <IOperationsService>(m => m.MoveAsync( It.Is <IReadOnlyDictionary <string, string> >(d => d.ContainsKey(FilePath) && d[FilePath] == newFilePath))) .Verifiable(); _autoMocker .Setup <IPathService, string>(m => m.GetFileName(FilePath)) .Returns(FileName); _autoMocker .Setup <IPathService, string>(m => m.Combine(It.IsAny <string>(), It.IsAny <string>())) .Returns <string, string>((a, b) => $"{a}/{b}"); _autoMocker .Setup <INodeService, bool>(m => m.CheckIfExists(It.IsAny <string>())) .Returns <string>(existingFiles.Contains); _autoMocker .Setup <IHomeDirectoryProvider, string>(m => m.HomeDirectoryPath) .Returns(HomePath); var macTrashCanService = _autoMocker.CreateInstance <MacTrashCanService>(); await macTrashCanService.MoveToTrashAsync(new[] { FilePath }, CancellationToken.None); _autoMocker .Verify <IOperationsService>(m => m.MoveAsync( It.Is <IReadOnlyDictionary <string, string> >(d => d.ContainsKey(FilePath) && d[FilePath] == newFilePath)), Times.Once); }
public void TestUnmount(string drive, string command, string arguments) { _autoMocker .Setup <IProcessService>(m => m.Run(command, arguments)) .Verifiable(); _autoMocker .Setup <IEnvironmentDriveService, IReadOnlyList <DriveInfo> >(m => m.GetMountedDrives()) .Returns(Array.Empty <DriveInfo>()); var service = _autoMocker.CreateInstance <MacMountedDriveService>(); service.Unmount(drive); _autoMocker .Verify <IProcessService>(m => m.Run(command, arguments), Times.Once); }
public void VerifyJsonGetsNotSavedInClipboardWhenUserSaysNo() { var mocker = new AutoMocker(); var userData = new List <AudioDramaUserData> { new AudioDramaUserData(Guid.Empty, true, false), new AudioDramaUserData(Guid.Empty, false, true), }; mocker .GetMock <ICache <IEnumerable <AudioDramaUserData> > >() .Setup(x => x.Load()) .Returns(userData); var sut = mocker.CreateInstance <UserDataImportExport>(); sut.ExportUserData(); mocker.GetMock <IYesNoDialog>().Raise(x => x.NoClicked += null, this, EventArgs.Empty); var json = JsonConvert.SerializeObject(userData); mocker.Verify <IClipboardService>(x => x.SetClipboardText(json), Times.Never); }
public async Task TestCopy(string sourceFilePath, string clipboardString) { _autoMocker .Setup <IClipboardService>(m => m.SetTextAsync(clipboardString)) .Verifiable(); _autoMocker .Setup <IEnvironmentService, string>(m => m.NewLine) .Returns(System.Environment.NewLine); var clipboardOperationsService = _autoMocker.CreateInstance <UnixClipboardOperationsService>(); await clipboardOperationsService.CopyFilesAsync(new[] { sourceFilePath }); _autoMocker .Verify <IClipboardService>(m => m.SetTextAsync(clipboardString), Times.Once); }
public async Task TestCopy() { _autoMocker .Setup <IClipboardService>(m => m.SetFilesAsync(It.Is <IReadOnlyList <string> >( l => l.Count == 2 && l.Contains(Directory) && l.Contains(File)))) .Verifiable(); var clipboardOperationsService = _autoMocker.CreateInstance <WindowsClipboardOperationsService>(); await clipboardOperationsService.CopyFilesAsync(new[] { Directory, File }); _autoMocker .Verify <IClipboardService>(m => m.SetFilesAsync(It.Is <IReadOnlyList <string> >( l => l.Count == 2 && l.Contains(Directory) && l.Contains(File))), Times.Once); }
public async Task GetByDateAsync_ShouldExecuteSuccessfully() { //Arrange var mocker = new AutoMocker(); var service = mocker.CreateInstance <AuditTrailService>(); var endDate = DateTime.UtcNow.Date; var startDate = endDate.Date.AddDays(-10); var date = endDate.Date.AddDays(-5); var ats = GetAuditTrails(date: date); mocker.GetMock <IAuditTrailBus>() .Setup(b => b.GetByDateAsync(startDate, endDate)) .ReturnsAsync(ats) .Verifiable(); var expectedResult = ats.Select(at => (AuditTrailResponse)at).ToList(); //Act var result = await service.GetByDateAsync(startDate, endDate).ConfigureAwait(false); //Assert new CompareLogic().Compare(expectedResult, result).AreEqual.Should().BeTrue(); mocker.Verify(); service.GetStatusCode().Should().BeEquivalentTo(HttpStatusCode.OK); }
public async Task UpdateUserAsync_PerfectWay_NoPhonesOrAddressInDb() { //Arrange var comparison = new CompareLogic(); var mocker = new AutoMocker(); var serviceMock = mocker.CreateInstance <UserService>(); var request = GetRequestToUpdate(TestCase.PerfectWay); var userDb = GetUserToUpdate(TestCase.PerfectWay); var expectedResult = GetResponseByUser(userDb); var phones = request.Phones .Select(phone => new Tuple <string, string>(phone.LocalCode, phone.Number)) .ToList(); mocker.GetMock <IUserBus>() .Setup(b => b.GetByIdAsync(request.Id ?? 0)) .ReturnsAsync(userDb) .Verifiable(); var token = new Entities.TokenModel(userDb.Id, userDb.Email, null); mocker.GetMock <IUserBus>() .Setup(b => b.GetTokenAsync()) .ReturnsAsync(token) .Verifiable(); mocker.GetMock <IUserBus>() .Setup(b => b.ExistsEmailAsync(request.Email, request.Id)) .ReturnsAsync(false) .Verifiable(); mocker.GetMock <IAddressBus>() .Setup(b => b.GetByInfoAsync(request.Address.Street, request.Address.Number, request.Address.Complement, request.Address.District, request.Address.City, request.Address.State, request.Address.PostalCode)) .ReturnsAsync((Entities.Address)null) .Verifiable(); mocker.GetMock <IPhoneBus>() .Setup ( b => b.GetByNumbersAsync ( It.Is <IList <Tuple <string, string> > >(p => comparison.Compare(p, phones).AreEqual) ) ) .ReturnsAsync(new List <Entities.Phone>()) .Verifiable(); mocker.GetMock <IUserBus>() .Setup(b => b.UpdateUserAsync(It.Is <Entities.User>(u => comparison.Compare(u, userDb).AreEqual))) .Verifiable(); //Act var result = await serviceMock.UpdateUserAsync(request).ConfigureAwait(false); //Assert serviceMock.IsSatisfied().Should().BeTrue(); Assert.True(comparison.Compare(expectedResult, result).AreEqual); mocker.Verify(); }