public void Given()
 {
     gateway = new Mock<Gateway>();
     gateway.SetReturnsDefault(true);
     obj = new Mock<StatefulObject>();
     obj.SetReturnsDefault(obj.Object);
 }
        public void when_finding_non_existing_assignment_then_returns_null()
        {
            var storage = new Mock<IBlobStorage>();
            storage.SetReturnsDefault<byte[]>(null);
            var dao = new OrderDao(() => new ConferenceRegistrationDbContext("OrderDaoFixture"), storage.Object, Mock.Of<ITextSerializer>());

            var dto = dao.FindOrderSeats(Guid.NewGuid());

            Assert.Null(dto);
        }
        public void UseAutofacLifetimeScopeInjectorDoesntAddWrappedMiddlewareInstancesToAppBuilder()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<TestMiddleware>();
            var container = builder.Build();
            var app = new Mock<IAppBuilder>();
            app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
            app.SetReturnsDefault(app.Object);

            app.Object.UseAutofacLifetimeScopeInjector(container);

            app.Verify(mock => mock.Use(It.IsAny<AutofacMiddleware<TestMiddleware>>(), It.IsAny<object[]>()), Times.Never);
        }
        public void CreateShareLink_CreatedLinkAndToken()
        {
            // arrange
            var pathHelper = new Mock<IPathHelper>();
            var hashService = new HashService();
            var shareService = new ShareService(pathHelper.Object, hashService);

            pathHelper.SetReturnsDefault("/user/share");

            // act
            var link = shareService.CreateShareLink("[email protected]");

            // assert
            link.Should().Contain("/user/share/[email protected]?key=");
        }
Example #5
0
        public void RecordCalculation_ProvideCalcuation_Should_populate_stream_with_csv()
        {
            var calculation = new Calculation { Answer = 2.1, Operation = "theOperation", Probability1 = 0.3, Probability2 = 0.6 };
            var memoryStream = new MemoryStream();
            var mockClock = new Mock<IClock>();

            mockClock.SetReturnsDefault(new DateTime(2000, 1, 10, 10, 12, 30));

            var logger = new Logger(memoryStream, mockClock.Object);
            logger.RecordCalculation(calculation);

            byte[] buffer = memoryStream.ToArray();
            var result = Encoding.UTF8.GetString(buffer, 0, buffer.Length);
            Assert.AreEqual("10/01/2000 10:12:30,0.3,0.6,2.1,theOperation\r\n", result);
        }
        public async Task CanPerformActivityAsync_PassDelegateParameter_ReturnTrue()
        {
            // Arrange
            var mockPredicate = new Mock<Func<UserAuthorisation, string, Task<bool>>>();
            mockPredicate.SetReturnsDefault(Task.FromResult(true));

            var user = new UserAuthorisation(userName);

            // Act
            var result = await user.CanPerformActivityAsync("READ", mockPredicate.Object);

            // Assert
            Assert.IsTrue(result);
            mockPredicate.Verify(p => p(user, "READ"), Times.Once);
        }
        public void ValidateShareKey_WrongKey()
        {
            var pathHelper = new Mock<IPathHelper>();
            var hashService = new HashService();
            var shareService = new ShareService(pathHelper.Object, hashService);

            pathHelper.SetReturnsDefault("/user/share");

            var key = "dd12113dcb92ffeb0d7afaf0261fAAAA";

            // act
            var result = shareService.ValidateShareKey("[email protected]", key);

            // assert
            result.Should().Be.False();
        }
        public void CanPerformActivity_MockDelegate_ReturnTrue()
        {
            // Arrange
            var mockCanPerformActivityHandler = new Mock<Func<UserAuthorisation,string, bool>>();
            mockCanPerformActivityHandler.SetReturnsDefault(true);

            var user = new UserAuthorisation(userName)
                .AddCanPerformActivityDelegate(mockCanPerformActivityHandler.Object);

            // Act
            var result = user.CanPerformActivity("READ");

            // Assert
            Assert.IsTrue(result);
            mockCanPerformActivityHandler.Verify(u => u(user, "READ"), Times.Once);
        }
        public void SendAfterOpenDoesBehavesCorrectlyForConfiguredQueuingBehavior(QueuingBehavior queuingBehavior, int expectedCounter)
        {
            var perfCounters = new Mock<IPerformanceCounterManager>();
            var queueLengthCounter = new Mock<IPerformanceCounter>();
            var counterIncrementCount = 0;
            queueLengthCounter.Setup(c => c.Increment()).Callback(() => counterIncrementCount++);
            perfCounters.DefaultValue = DefaultValue.Mock;
            perfCounters.SetReturnsDefault(new NoOpPerformanceCounter());
            perfCounters.SetupAllProperties();
            perfCounters.Setup(pc => pc.ScaleoutSendQueueLength).Returns(queueLengthCounter.Object);

            var stream = new ScaleoutStream(new TraceSource("Queue"), "0", queuingBehavior, 1000, perfCounters.Object);

            stream.Send(_ => TaskAsyncHelper.Empty, null);

            stream.Open();

            stream.Send(_ => TaskAsyncHelper.Empty, null).Wait();

            Assert.Equal(expectedCounter, counterIncrementCount);
        }
        public void Should_Delete_Media_With_Access_Rules()
        {
            RunActionInTransaction(session =>
                {
                    var uow = new DefaultUnitOfWork(session);
                    var repository = new DefaultRepository(uow);
                    var accessControlService = new Mock<IAccessControlService>().Object;
                    var commandContext = new Mock<ICommandContext>().Object;
                    var cmsConfiguration = Container.Resolve<ICmsConfiguration>();
                    var httpContextAccessor = new Mock<IHttpContextAccessor>();
                    httpContextAccessor.SetReturnsDefault("http://wwww.bcms.com/uploads/trash");

                    var file = TestDataProvider.CreateNewMediaFileWithAccessRules(3);
                    session.SaveOrUpdate(file);
                    session.Flush();
                    session.Clear();

                    var mediaService = new DefaultMediaService(repository, uow, accessControlService, cmsConfiguration);
                    var command = new DeleteMediaCommand(mediaService);
                    command.Repository = repository;
                    command.UnitOfWork = uow;
                    command.Context = commandContext;

                    var result = command.Execute(new DeleteMediaCommandRequest
                                        {
                                            Id = file.Id,
                                            Version = file.Version
                                        });

                    Assert.IsTrue(result);

                    session.Clear();

                    var deletedFile = session.Query<MediaFile>().FirstOrDefault(f => f.Id == file.Id && !f.IsDeleted);
                    Assert.IsNull(deletedFile);
                });
        }
Example #11
0
		public void ReturnsDefaultValueOnProperty()
		{
			var mock = new Mock<IFoo>();
			mock.SetReturnsDefault(int.MinValue);

			Assert.Equal(int.MinValue, mock.Object.Value);
		}
Example #12
0
		public void ReturnsDefaultValueType()
		{
			var mock = new Mock<IFoo>();
			mock.SetReturnsDefault(true);

			Assert.Equal(true, mock.Object.ReturnBool());
		}
Example #13
0
		public void ReturnsDefaultReferenceValue()
		{
			var mock = new Mock<IFoo>();
			mock.SetReturnsDefault<IList<int>>(new List<int>());

			Assert.NotNull(mock.Object.ReturnIntList());
		}
        public void UseMiddlewareFromContainerRequiresInjectorRegistrationFirst()
        {
            var app = new Mock<IAppBuilder>();
            app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
            app.SetReturnsDefault(app.Object);

            Assert.Throws<InvalidOperationException>(() => app.Object.UseMiddlewareFromContainer<TestMiddleware>());
        }
        public async Task IsInRoleAsync_AddDelegateDuringInitialisation_ReturnTrue()
        {
            // Arrange
            var mockPredicate = new Mock<Func<UserAuthorisation, string, Task<bool>>>();
            mockPredicate.SetReturnsDefault(Task.FromResult(true));

            var user = new UserAuthorisation(userName)
                .AddAsyncIsInRoleDelegate(mockPredicate.Object);

            // Act
            var result = await user.IsInRoleAsync("DATAREADER");

            // Assert
            Assert.IsTrue(result);
            mockPredicate.Verify(p => p(user, "DATAREADER"), Times.Once);
        }
        public void UseAutofacLifetimeScopeInjectorShowsInjectorRegistered()
        {
            var app = new Mock<IAppBuilder>();
            app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
            app.SetReturnsDefault(app.Object);

            var container = new ContainerBuilder().Build();
            app.Object.UseAutofacLifetimeScopeInjector(container);
            Assert.True(app.Object.IsAutofacLifetimeScopeInjectorRegistered());
        }
        public void IsInRole_PassMockDelegateIntoCall_ReturnTrue()
        {
            // Arrange
            var mockIsInRoleHandler = new Mock<Func<UserAuthorisation, string, bool>>();
            mockIsInRoleHandler.SetReturnsDefault(true);

            var user = new UserAuthorisation(userName);

            // Act
            var result = user.IsInRole("DATAREADER", mockIsInRoleHandler.Object);

            // Assert
            Assert.IsTrue(result);
            mockIsInRoleHandler.Verify(u => u(user, "DATAREADER"), Times.Once);
        }
        public void UseMiddlewareFromContainerAddsSingleWrappedMiddlewareInstanceToAppBuilder()
        {
            var app = new Mock<IAppBuilder>();
            app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
            app.SetReturnsDefault(app.Object);

            var container = new ContainerBuilder().Build();
            app.Object.UseAutofacLifetimeScopeInjector(container);
            app.Object.UseMiddlewareFromContainer<TestMiddleware>();

            app.Verify(mock => mock.Use(typeof(AutofacMiddleware<TestMiddleware>)), Times.Once);
        }
Example #19
0
 public void Blah()
 {
     Mock myMock = new Mock<IComparable>();
     myMock.SetReturnsDefault(true);
     var myMock2 = new Mock<Mock>();
 }
        public void Setup()
        {
            //var path = @"D:\Program Files\Microsoft SQL Server\MSSQL.2\MSSQL\Data\Sicemed_Snapshot.ss";
            var path = @"C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\Sicemed_Snapshot.ss";
            CreateDatabaseSnapshot("Sicemed_Snapshot", "SicemedTest", path);
            var logLevel = LogManager.GetRepository().Threshold;
            LogManager.GetRepository().Threshold = Level.Off;

            CurrentSessionContext.Bind(SessionFactory.OpenSession());

            var installer = new ApplicationInstaller();
            installer.SessionFactory = SessionFactory;

            var membershipMailerMock = new Mock<IMembershipMailer>();
            membershipMailerMock.SetReturnsDefault(new MailMessage("[email protected]", "[email protected]"));

            installer.MembershipService = new MembershipService(SessionFactory,
                                                                membershipMailerMock.Object,
                                                                new Mock<IFormAuthenticationStoreService>().Object);
            installer.Install(DatabaseConfiguration);

            LogManager.GetRepository().Threshold = logLevel;

            new RijndaelEngine("WAL");
            _membershipMailer = new Mock<IMembershipMailer>();
            _membershipMailer.SetReturnsDefault(new MailMessage("[email protected]", "[email protected]"));
            var formsService = new Mock<IFormAuthenticationStoreService>();
            _membershipService = new MembershipService(SessionFactory,
                                                       _membershipMailer.Object,
                                                       formsService.Object);
        }
        public void IsInRole_MockDelegate_ReturnFalse()
        {
            // Arrange
            var mockIsInRoleHandler = new Mock<Func<UserAuthorisation, string, bool>>();
            mockIsInRoleHandler.SetReturnsDefault(false);

            var user = new UserAuthorisation(userName)
                .AddIsInRoleDelegate(mockIsInRoleHandler.Object);

            // Act
            var result = user.IsInRole("DATAREADER");

            // Assert
            Assert.IsFalse(result);
            mockIsInRoleHandler.Verify(u => u(user, "DATAREADER"), Times.Once);
        }
        public void UseAutofacMiddlewareAddsWrappedMiddlewareInstancesToAppBuilder()
        {
            var builder = new ContainerBuilder();
            builder.RegisterType<TestMiddleware>();
            var container = builder.Build();
            var app = new Mock<IAppBuilder>();
            app.Setup(mock => mock.Properties).Returns(new Dictionary<string, object>());
            app.Setup(mock => mock.Use(typeof(AutofacMiddleware<TestMiddleware>)));
            app.SetReturnsDefault(app.Object);

            app.Object.UseAutofacMiddleware(container);

            app.VerifyAll();
        }