Exemplo n.º 1
0
        public void EnsureCollectionCanBeSerialized()
        {
            var pollSubmissionResponseFactory = new Mock <IObjectFactory <IPollSubmissionResponse> >();

            pollSubmissionResponseFactory.Setup(_ => _.CreateChild(It.IsAny <object[]>()))
            .Returns <object[]>(_ => DataPortal.CreateChild <PollSubmissionResponse>(_[0] as IPollOption));

            var builder = new ContainerBuilder();

            builder.Register <IEntities>(_ => Mock.Of <IEntities>());
            builder.Register <IObjectFactory <IPollSubmissionResponse> >(_ => pollSubmissionResponseFactory.Object);

            using (new ObjectActivator(builder.Build(), new ActivatorCallContext())
                   .Bind(() => ApplicationContext.DataPortalActivator))
            {
                var responses = DataPortal.CreateChild <PollSubmissionResponseCollection>(
                    PollSubmissionResponseCollectionTests.CreateOptions());
                var formatter = new MobileFormatter();

                using (var stream = new MemoryStream())
                {
                    formatter.Serialize(stream, responses);
                    stream.Position = 0;
                    var newResponses = formatter.Deserialize(stream) as PollSubmissionResponseCollection;
                    Assert.AreEqual(1, newResponses.Count, nameof(newResponses.Count));
                    Assert.AreEqual(responses[0].OptionText, newResponses[0].OptionText, nameof(IPollSubmissionResponse.OptionText));
                }
            }
        }
Exemplo n.º 2
0
        public void Clear()
        {
            var pollSubmissionResponseFactory = new Mock <IObjectFactory <IPollSubmissionResponse> >();

            pollSubmissionResponseFactory.Setup(_ => _.CreateChild(It.IsAny <object[]>()))
            .Returns <object[]>(_ => DataPortal.CreateChild <PollSubmissionResponse>(_[0] as IPollOption));

            var builder = new ContainerBuilder();

            builder.Register <IEntities>(_ => Mock.Of <IEntities>());
            builder.Register <IObjectFactory <IPollSubmissionResponse> >(_ => pollSubmissionResponseFactory.Object);

            using (new ObjectActivator(builder.Build(), new ActivatorCallContext())
                   .Bind(() => ApplicationContext.DataPortalActivator))
            {
                var responses = DataPortal.CreateChild <PollSubmissionResponseCollection>(
                    PollSubmissionResponseCollectionTests.CreateOptions());
                responses.Clear();
            }
        }
Exemplo n.º 3
0
        public void Create()
        {
            var pollSubmissionResponseFactory = new Mock <IObjectFactory <IPollSubmissionResponse> >(MockBehavior.Strict);

            pollSubmissionResponseFactory.Setup(_ => _.CreateChild(It.IsAny <object[]>()))
            .Returns <object[]>(_ => DataPortal.CreateChild <PollSubmissionResponse>(_[0] as IPollOption));

            var builder = new ContainerBuilder();

            builder.Register <IEntities>(_ => Mock.Of <IEntities>());
            builder.Register <IObjectFactory <IPollSubmissionResponse> >(_ => pollSubmissionResponseFactory.Object);

            using (new ObjectActivator(builder.Build(), new ActivatorCallContext())
                   .Bind(() => ApplicationContext.DataPortalActivator))
            {
                var responses = DataPortal.CreateChild <PollSubmissionResponseCollection>(
                    PollSubmissionResponseCollectionTests.CreateOptions());

                Assert.AreEqual(1, responses.Count, nameof(responses.Count));
            }

            pollSubmissionResponseFactory.VerifyAll();
        }