public void TestAtAftaleGetAllBySystemHenterAftaler() { IEnumerable <AftaleProxy> appointmentProxyCollection = _fixture.Build <AftaleProxy>() .With(m => m.FraTidspunkt, DateTime.MinValue) .With(m => m.TilTidspunkt, DateTime.MaxValue) .CreateMany(_random.Next(15, 25)) .ToList(); IKalenderRepository sut = CreateSut(appointmentProxyCollection); Assert.That(sut, Is.Not.Null); int systemNo = _fixture.Create <int>(); DateTime fromDate = DateTime.Now.AddDays(_random.Next(1, 30) * -1); IEnumerable <IAftale> result = sut.AftaleGetAllBySystem(systemNo, fromDate); // ReSharper disable PossibleMultipleEnumeration Assert.That(result, Is.Not.Null); Assert.That(result, Is.Not.Empty); Assert.That(result, Is.EqualTo(appointmentProxyCollection)); // ReSharper restore PossibleMultipleEnumeration IDbCommandTestExecutor commandTester = new DbCommandTestBuilder("SELECT ca.SystemNo,ca.CalId,ca.Date,ca.FromTime,ca.ToTime,ca.Properties,ca.Subject,ca.Note,s.Title AS SystemTitle,s.Properties AS SystemProperties FROM Calapps AS ca FORCE INDEX(IX_Calapps_SystemNo_Date) INNER JOIN Systems AS s ON s.SystemNo=ca.SystemNo WHERE ca.SystemNo=@systemNo AND ca.Date>=@date ORDER BY ca.Date DESC,ca.FromTime DESC,ca.ToTime DESC,ca.CalId DESC") .AddSmallIntDataParameter("@systemNo", systemNo, 2) .AddDateParameter("@date", fromDate) .Build(); _dataProviderMock.AssertWasCalled(m => m.GetCollection <AftaleProxy>(Arg <MySqlCommand> .Matches(cmd => commandTester.Run(cmd))), opt => opt.Repeat.Once()); }
public void TestThatDeltagereGetAppointmentUsersWhenMapDataHasBeenCalledAndMapRelationsHasNotBeenCalled() { IAftaleProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); int systemNo = _fixture.Create <int>(); int calId = _fixture.Create <int>(); MySqlDataReader dataReader = CreateMySqlDataReader(systemNo, calId, subject: _fixture.Create <string>()); ISystemProxy systemProxyMock = MockRepository.GenerateMock <ISystemProxy>(); systemProxyMock.Stub(m => m.Nummer) .Return(systemNo) .Repeat.Any(); IEnumerable <BrugeraftaleProxy> appointmentUserCollection = _fixture.CreateMany <BrugeraftaleProxy>(_random.Next(3, 7)).ToList(); IMySqlDataProvider dataProvider = CreateMySqlDataProvider(systemProxyMock, appointmentUserCollection); sut.MapData(dataReader, dataProvider); IEnumerable <IBrugeraftale> result = sut.Deltagere; // ReSharper disable PossibleMultipleEnumeration Assert.That(result, Is.Not.Null); Assert.That(result, Is.Not.Empty); Assert.That(result, Is.EqualTo(appointmentUserCollection)); // ReSharper restore PossibleMultipleEnumeration IDbCommandTestExecutor commandTester = new DbCommandTestBuilder("SELECT cm.SystemNo,cm.CalId,cm.UserId,cm.Properties,ca.Date,ca.FromTime,ca.ToTime,ca.Properties AS AppointmentProperties,ca.Subject,ca.Note,cu.UserName,cu.Name AS UserFullname,cu.Initials AS UserInitials,s.Title AS SystemTitle,s.Properties AS SystemProperties FROM Calmerge AS cm INNER JOIN Calapps AS ca ON ca.SystemNo=cm.SystemNo AND ca.CalId=cm.CalId INNER JOIN Calusers AS cu ON cu.SystemNo=cm.SystemNo AND cu.UserId=cm.UserId INNER JOIN Systems AS s ON s.SystemNo=cm.SystemNo WHERE cm.SystemNo=@systemNo AND cm.CalId=@calId") .AddSmallIntDataParameter("@systemNo", systemNo, 2) .AddIntDataParameter("@calId", calId, 8) .Build(); dataProvider.AssertWasCalled(m => m.GetCollection <BrugeraftaleProxy>(Arg <MySqlCommand> .Matches(cmd => commandTester.Run(cmd))), opt => opt.Repeat.Once()); }
public void TestThatMapRelationsMapsAppointmentUsers() { int systemNo = _fixture.Create <int>(); int calId = _fixture.Create <int>(); IAftaleProxy sut = CreateSut(systemNo, calId); Assert.That(sut, Is.Not.Null); IEnumerable <BrugeraftaleProxy> appointmentUserCollection = _fixture.CreateMany <BrugeraftaleProxy>(_random.Next(3, 7)).ToList(); IMySqlDataProvider dataProvider = CreateMySqlDataProvider(appointmentUserCollection: appointmentUserCollection); sut.MapRelations(dataProvider); Assert.That(sut.Deltagere, Is.Not.Null); Assert.That(sut.Deltagere, Is.Not.Empty); Assert.That(sut.Deltagere, Is.EqualTo(appointmentUserCollection)); IDbCommandTestExecutor commandTester = new DbCommandTestBuilder("SELECT cm.SystemNo,cm.CalId,cm.UserId,cm.Properties,ca.Date,ca.FromTime,ca.ToTime,ca.Properties AS AppointmentProperties,ca.Subject,ca.Note,cu.UserName,cu.Name AS UserFullname,cu.Initials AS UserInitials,s.Title AS SystemTitle,s.Properties AS SystemProperties FROM Calmerge AS cm INNER JOIN Calapps AS ca ON ca.SystemNo=cm.SystemNo AND ca.CalId=cm.CalId INNER JOIN Calusers AS cu ON cu.SystemNo=cm.SystemNo AND cu.UserId=cm.UserId INNER JOIN Systems AS s ON s.SystemNo=cm.SystemNo WHERE cm.SystemNo=@systemNo AND cm.CalId=@calId") .AddSmallIntDataParameter("@systemNo", systemNo, 2) .AddIntDataParameter("@calId", calId, 8) .Build(); dataProvider.AssertWasCalled(m => m.GetCollection <BrugeraftaleProxy>(Arg <MySqlCommand> .Matches(cmd => commandTester.Run(cmd))), opt => opt.Repeat.Once()); }
public void TestThatMapRelationsCallsCloneOnDataProvider() { IAftaleProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); IMySqlDataProvider dataProvider = CreateMySqlDataProvider(); sut.MapRelations(dataProvider); dataProvider.AssertWasCalled(m => m.Clone(), opt => opt.Repeat.Once()); }
public void TestThatDeltagereCallsCloneOnDataProviderWhenMapDataHasBeenCalledAndMapRelationsHasNotBeenCalled() { IAftaleProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); int systemNo = _fixture.Create <int>(); int calId = _fixture.Create <int>(); MySqlDataReader dataReader = CreateMySqlDataReader(systemNo, calId, subject: _fixture.Create <string>()); IMySqlDataProvider dataProvider = CreateMySqlDataProvider(); sut.MapData(dataReader, dataProvider); IEnumerable <IBrugeraftale> result = sut.Deltagere; Assert.That(result, Is.Not.Null); dataProvider.AssertWasCalled(m => m.Clone(), opt => opt.Repeat.Once()); }
public void TestAtSystemGetAllHenterSystemer() { IEnumerable <SystemProxy> systemProxyCollection = _fixture.CreateMany <SystemProxy>(_random.Next(5, 10)).ToList(); IMySqlDataProvider mySqlDataProvider = CreateMySqlDataProvider(systemProxyCollection); IFællesRepository sut = new FællesRepository(CreateChannelFactory(), mySqlDataProvider, CreateDomainObjectBuilder()); Assert.That(sut, Is.Not.Null); IEnumerable <ISystem> result = sut.SystemGetAll(); // ReSharper disable PossibleMultipleEnumeration Assert.That(result, Is.Not.Null); Assert.That(result, Is.Not.Empty); Assert.That(result.Count(), Is.EqualTo(systemProxyCollection.Count())); Assert.That(result, Is.EqualTo(systemProxyCollection)); // ReSharper restore PossibleMultipleEnumeration IDbCommandTestExecutor expectedCommandTester = new DbCommandTestBuilder("SELECT SystemNo,Title,Properties FROM Systems ORDER BY SystemNo").Build(); mySqlDataProvider.AssertWasCalled(m => m.GetCollection <SystemProxy>(Arg <MySqlCommand> .Matches(cmd => expectedCommandTester.Run(cmd))), opt => opt.Repeat.Once()); }
public void TestThatCreateCreatesCalenderUserProxy(bool hasUserName) { IBrugerProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); int systemNo = _fixture.Create <int>(); int userId = _fixture.Create <int>(); string userName = hasUserName ? _fixture.Create <string>() : null; string name = _fixture.Create <string>(); string initials = _fixture.Create <string>(); MySqlDataReader dataReader = CreateMySqlDataReader(systemNo, userId, userName, name, initials); ISystemProxy systemProxy = MockRepository.GenerateMock <ISystemProxy>(); IMySqlDataProvider dataProvider = CreateMySqlDataProvider(systemProxy); IBrugerProxy result = sut.Create(dataReader, dataProvider, "UserId", "Initials", "Name", "UserName", "SystemNo", "Title", "Properties"); Assert.That(result, Is.Not.Null); Assert.That(result.System, Is.Not.Null); Assert.That(result.System, Is.EqualTo(systemProxy)); Assert.That(result.Id, Is.EqualTo(userId)); if (hasUserName) { Assert.That(result.UserName, Is.Not.Null); Assert.That(result.UserName, Is.Not.Empty); Assert.That(result.UserName, Is.EqualTo(userName)); } else { Assert.That(result.UserName, Is.Null); } Assert.That(result.Navn, Is.Not.Null); Assert.That(result.Navn, Is.Not.Empty); Assert.That(result.Navn, Is.EqualTo(name)); Assert.That(result.Initialer, Is.Not.Null); Assert.That(result.Initialer, Is.Not.Empty); Assert.That(result.Initialer, Is.EqualTo(initials)); dataReader.AssertWasCalled(m => m.GetInt32(Arg <string> .Is.Equal("UserId")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetOrdinal(Arg <string> .Is.Equal("UserName")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.IsDBNull(Arg <int> .Is.Equal(2)), opt => opt.Repeat.Once()); if (hasUserName) { dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("UserName")), opt => opt.Repeat.Once()); } else { dataReader.AssertWasNotCalled(m => m.GetString(Arg <string> .Is.Equal("UserName"))); } dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("Name")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("Initials")), opt => opt.Repeat.Once()); dataProvider.AssertWasCalled(m => m.Create( Arg <ISystemProxy> .Is.TypeOf, Arg <MySqlDataReader> .Is.Equal(dataReader), Arg <string[]> .Matches(e => e != null && e.Length == 3 && e[0] == "SystemNo" && e[1] == "Title" && e[2] == "Properties")), opt => opt.Repeat.Once()); }
public void TestAtMapDataMapperBrugeraftaleProxy(bool hasProperties) { IBrugeraftaleProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); int systemNo = _fixture.Create <int>(); int calId = _fixture.Create <int>(); int userId = _fixture.Create <int>(); int? properties = hasProperties ? _fixture.Create <int>() : (int?)null; MySqlDataReader dataReader = CreateMySqlDataReader(systemNo, calId, userId, properties); ISystemProxy systemProxy = MockRepository.GenerateMock <ISystemProxy>(); IAftaleProxy appointmentProxy = MockRepository.GenerateMock <IAftaleProxy>(); IBrugerProxy calenderUserProxy = MockRepository.GenerateMock <IBrugerProxy>(); IMySqlDataProvider dataProvider = CreateMySqlDataProvider(systemProxy, appointmentProxy, calenderUserProxy); sut.MapData(dataReader, dataProvider); Assert.That(sut.System, Is.Not.Null); Assert.That(sut.System, Is.EqualTo(systemProxy)); Assert.That(sut.Aftale, Is.Not.Null); Assert.That(sut.Aftale, Is.EqualTo(appointmentProxy)); Assert.That(sut.Bruger, Is.Not.Null); Assert.That(sut.Bruger, Is.EqualTo(calenderUserProxy)); if (hasProperties) { Assert.That(sut.Properties, Is.EqualTo(properties)); } else { Assert.That(sut.Properties, Is.EqualTo(0)); } dataReader.AssertWasCalled(m => m.GetOrdinal(Arg <string> .Is.Equal("Properties")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.IsDBNull(Arg <int> .Is.Equal(3)), opt => opt.Repeat.Once()); if (hasProperties) { dataReader.AssertWasCalled(m => m.GetInt32(Arg <string> .Is.Equal("Properties")), opt => opt.Repeat.Once()); } else { dataReader.AssertWasNotCalled(m => m.GetInt32(Arg <string> .Is.Equal("Properties"))); } dataProvider.AssertWasCalled(m => m.Create( Arg <ISystemProxy> .Is.TypeOf, Arg <MySqlDataReader> .Is.Equal(dataReader), Arg <string[]> .Matches(e => e != null && e.Length == 3 && e[0] == "SystemNo" && e[1] == "SystemTitle" && e[2] == "SystemProperties")), opt => opt.Repeat.Once()); dataProvider.AssertWasCalled(m => m.Create( Arg <IAftaleProxy> .Is.TypeOf, Arg <MySqlDataReader> .Is.Equal(dataReader), Arg <string[]> .Matches(e => e != null && e.Length == 10 && e[0] == "CalId" && e[1] == "Date" && e[2] == "FromTime" && e[3] == "ToTime" && e[4] == "AppointmentProperties" && e[5] == "Subject" && e[6] == "Note" && e[7] == "SystemNo" && e[8] == "SystemTitle" && e[9] == "SystemProperties")), opt => opt.Repeat.Once()); dataProvider.AssertWasCalled(m => m.Create( Arg <IBrugerProxy> .Is.TypeOf, Arg <MySqlDataReader> .Is.Equal(dataReader), Arg <string[]> .Matches(e => e != null && e.Length == 7 && e[0] == "UserId" && e[1] == "UserInitials" && e[2] == "UserFullname" && e[3] == "UserName" && e[4] == "SystemNo" && e[5] == "SystemTitle" && e[6] == "SystemProperties")), opt => opt.Repeat.Once()); }
public void TestThatCreateCreatesCalenderUserProxy(bool hasProperties, bool hasNote) { IAftaleProxy sut = CreateSut(); Assert.That(sut, Is.Not.Null); int systemNo = _fixture.Create <int>(); int calId = _fixture.Create <int>(); DateTime fromDateTime = DateTime.Today.AddDays(_random.Next(1, 30)).AddHours(_random.Next(8, 16)).AddMinutes(_random.Next(0, 3) * 15); TimeSpan duration = new TimeSpan(0, 0, _random.Next(1, 3) * 15, 0); int? properties = hasProperties ? _fixture.Create <int>() : (int?)null; string subject = _fixture.Create <string>(); string note = hasNote ? _fixture.Create <string>() : null; MySqlDataReader dataReader = CreateMySqlDataReader(systemNo, calId, fromDateTime, duration, properties, subject, note); ISystemProxy systemProxy = MockRepository.GenerateMock <ISystemProxy>(); IMySqlDataProvider dataProvider = CreateMySqlDataProvider(systemProxy); IAftaleProxy result = sut.Create(dataReader, dataProvider, "CalId", "Date", "FromTime", "ToTime", "Properties", "Subject", "Note", "SystemNo", "SystemTitle", "SystemProperties"); Assert.That(result.System, Is.Not.Null); Assert.That(result.System, Is.EqualTo(systemProxy)); Assert.That(result.Id, Is.EqualTo(calId)); Assert.That(result.FraTidspunkt, Is.EqualTo(fromDateTime)); Assert.That(result.TilTidspunkt, Is.EqualTo(fromDateTime.Add(duration))); if (hasProperties) { Assert.That(result.Properties, Is.EqualTo(properties)); } else { Assert.That(result.Properties, Is.EqualTo(0)); } Assert.That(result.Emne, Is.Not.Null); Assert.That(result.Emne, Is.Not.Empty); Assert.That(result.Emne, Is.EqualTo(subject)); if (hasNote) { Assert.That(result.Notat, Is.Not.Null); Assert.That(result.Notat, Is.Not.Empty); Assert.That(result.Notat, Is.EqualTo(note)); } else { Assert.That(result.Notat, Is.Null); } dataReader.AssertWasCalled(m => m.GetInt32(Arg <string> .Is.Equal("CalId")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetMySqlDateTime(Arg <string> .Is.Equal("Date")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetTimeSpan(Arg <string> .Is.Equal("FromTime")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetTimeSpan(Arg <string> .Is.Equal("ToTime")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetOrdinal(Arg <string> .Is.Equal("Properties")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.IsDBNull(Arg <int> .Is.Equal(5)), opt => opt.Repeat.Once()); if (hasProperties) { dataReader.AssertWasCalled(m => m.GetInt32(Arg <string> .Is.Equal("Properties")), opt => opt.Repeat.Once()); } else { dataReader.AssertWasNotCalled(m => m.GetInt32(Arg <string> .Is.Equal("Properties"))); } dataReader.AssertWasCalled(m => m.GetOrdinal(Arg <string> .Is.Equal("Subject")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.IsDBNull(Arg <int> .Is.Equal(6)), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("Subject")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.GetOrdinal(Arg <string> .Is.Equal("Note")), opt => opt.Repeat.Once()); dataReader.AssertWasCalled(m => m.IsDBNull(Arg <int> .Is.Equal(7)), opt => opt.Repeat.Once()); if (hasNote) { dataReader.AssertWasCalled(m => m.GetString(Arg <string> .Is.Equal("Note")), opt => opt.Repeat.Once()); } else { dataReader.AssertWasNotCalled(m => m.GetString(Arg <string> .Is.Equal("Note"))); } dataProvider.AssertWasCalled(m => m.Create( Arg <ISystemProxy> .Is.TypeOf, Arg <MySqlDataReader> .Is.Equal(dataReader), Arg <string[]> .Matches(e => e != null && e.Length == 3 && e[0] == "SystemNo" && e[1] == "SystemTitle" && e[2] == "SystemProperties")), opt => opt.Repeat.Once()); dataProvider.AssertWasNotCalled(m => m.Clone()); }