public void ManageSqliteSourceViewModel_TestToModelItemNull() { //arrange var gd = Guid.NewGuid(); _targetAsyncWorker.Item = null; var expectedType = enSourceType.SQLiteDatabase; var expectedAuthenticationType = AuthenticationType.User; _targetAsyncWorker.AuthenticationType = expectedAuthenticationType; var expectedServerName = "serverName"; _targetAsyncWorker.ServerName = new ComputerName() { Name = expectedServerName }; var expectedPassword = "******"; _targetAsyncWorker.Password = expectedPassword; var expectedUserName = "******"; _targetAsyncWorker.UserName = expectedUserName; var expectedPath = "somePath"; _targetAsyncWorker.Path = expectedPath; var expectedName = "someName"; _targetAsyncWorker.ResourceName = expectedName; var expectedDbName = "someDbName"; _targetAsyncWorker.DatabaseName = expectedDbName; _targetAsyncWorker.SelectedGuid = gd; //act var value = _targetAsyncWorker.ToModel(); //assert Assert.AreSame(_targetAsyncWorker.Item, value); Assert.AreEqual(expectedAuthenticationType, value.AuthenticationType); Assert.AreEqual(expectedPassword, value.Password); Assert.AreEqual(expectedUserName, value.UserName); Assert.AreEqual(expectedType, value.Type); Assert.AreEqual(expectedPath, value.Path); Assert.AreEqual(expectedName, value.Name); Assert.AreEqual(expectedDbName, value.DbName); Assert.AreEqual(gd, value.Id); }
public void ManageSqliteSourceViewModel_dbSourceNotNull() { var expectedId = Guid.NewGuid(); _asyncWorkerMock = new Mock <IAsyncWorker>(); _updateManagerMock = new Mock <IManageDatabaseSourceModel>(); _aggregatorMock = new Mock <IEventAggregator>(); _dbSourceMock = new Mock <IDbSource>(); _requestServiceNameViewMock = new Mock <IRequestServiceNameViewModel>(); _requestServiceNameView = Task.FromResult(_requestServiceNameViewMock.Object); _updateManagerMock.Setup(it => it.GetComputerNames()) .Returns(new List <string>() { "someName1", "someName2" }); _dbSourceMock.SetupGet(it => it.Name).Returns("someDbSourceName"); _dbSourceMock.SetupGet(it => it.ConnectionTimeout).Returns(30); _dbSourceMock.Setup(it => it.Id).Returns(expectedId); _updateManagerMock.Setup(model => model.FetchDbSource(It.IsAny <Guid>())) .Returns(_dbSourceMock.Object); _asyncWorkerMock.Setup(worker => worker.Start( It.IsAny <Func <IDbSource> >(), It.IsAny <Action <IDbSource> >())) .Callback <Func <IDbSource>, Action <IDbSource> >((func, action) => { var dbSource = func.Invoke(); action?.Invoke(dbSource); }); _targetAsyncWorker = new ManageSqliteSourceViewModel( _updateManagerMock.Object, _aggregatorMock.Object, _dbSourceMock.Object, _asyncWorkerMock.Object); //arrange var expectedAuthenticationType = AuthenticationType.Anonymous; var expectedServerName = "expectedServerName"; var expectedPassword = "******"; var expectedUsername = "******"; var expectedType = enSourceType.SQLiteDatabase; var expectedPath = "somePath"; var expectedDbName = "someDbName"; _targetAsyncWorker.AuthenticationType = expectedAuthenticationType; _targetAsyncWorker.ServerName = new ComputerName() { Name = expectedServerName }; _targetAsyncWorker.Password = expectedPassword; _targetAsyncWorker.UserName = expectedUsername; _targetAsyncWorker.Path = expectedPath; _targetAsyncWorker.DatabaseName = expectedDbName; _targetAsyncWorker.Item = _dbSourceMock.Object; //act var value = _targetAsyncWorker.ToModel(); //assert Assert.AreSame(_targetAsyncWorker.Item, value); Assert.AreEqual(expectedAuthenticationType, value.AuthenticationType); Assert.AreEqual(expectedPassword, value.Password); Assert.AreEqual(expectedType, value.Type); Assert.AreEqual(expectedDbName, value.DbName); Assert.AreEqual(expectedId, value.Id); }