private void InsertIntoOneToManyTables(
            long personId,
            Person person)
        {
            // Why the null checks?
            // When updating, the sattelite classes are optional (bar
            // ContactDetail).
            // Since validation is the responsibility of a level above,
            // we don't have to worry about this.
            if (person.Consent != null)
            {
                // 3) Consent
                this.loggerProvider.Debug(
                    $"Invoking " +
                    $"{nameof(IDataCaptureDatabaseAdapter)}.{nameof(IDataCaptureDatabaseAdapter.CreateConsent)}...");

                CreateConsentResult createConsentResult =
                    this.dataCaptureDatabaseAdapter.CreateConsent(
                        personId,
                        DateTime.UtcNow,
                        person.Consent.GdprConsentDeclared,
                        person.Consent.GdprConsentGiven);

                this.loggerProvider.Info($"Created: {createConsentResult}.");
            }

            if (person.Cookie != null)
            {
                // 4) Cookie
                this.loggerProvider.Debug(
                    $"Invoking " +
                    $"{nameof(IDataCaptureDatabaseAdapter)}.{nameof(IDataCaptureDatabaseAdapter.CreateCookie)}...");

                CreateCookieResult createCookieResult =
                    this.dataCaptureDatabaseAdapter.CreateCookie(
                        personId,
                        DateTime.UtcNow,
                        person.Cookie.Captured,
                        person.Cookie.CookieIdentifier);

                this.loggerProvider.Info($"Created: {createCookieResult}.");
            }

            if (person.Route != null)
            {
                // 5) Route
                this.loggerProvider.Debug(
                    $"Invoking " +
                    $"{nameof(IDataCaptureDatabaseAdapter)}.{nameof(IDataCaptureDatabaseAdapter.CreateRoute)}...");

                CreateRouteResult createRouteResult =
                    this.dataCaptureDatabaseAdapter.CreateRoute(
                        personId,
                        DateTime.UtcNow,
                        person.Route.Captured,
                        person.Route.RouteIdentifier);

                this.loggerProvider.Info($"Created: {createRouteResult}.");
            }
        }
        /// <inheritdoc />
        public CreateRouteResult CreateRoute(
            long personId,
            DateTime created,
            DateTime captured,
            string routeIdentifier)
        {
            CreateRouteResult toReturn = null;

            object sprocParameters =
                new
            {
                Person_Id       = personId,
                Created         = created,
                Captured        = captured,
                RouteIdentifier = routeIdentifier,
            };

            toReturn =
                this.ExecuteStoredProcedureSingularResult <CreateRouteResult>(
                    "Create_Route",
                    sprocParameters);

            return(toReturn);
        }
コード例 #3
0
        public void Create_EmailAddressDoesNotExistAlready_NoExceptionThrown()
        {
            // Arrange
            ReadPersonResult readPersonResult = null;

            CreatePersonResult createPersonResult = new CreatePersonResult()
            {
                Id = 123,
            };

            CreateContactDetailResult createContactDetailResult =
                new CreateContactDetailResult()
            {
                Id = 456,
            };

            CreateConsentResult createConsentResult = new CreateConsentResult()
            {
                Id = 789,
            };

            CreateCookieResult createCookieResult = new CreateCookieResult()
            {
                Id = 345,
            };

            CreateRouteResult createRouteResult = new CreateRouteResult()
            {
                Id = 678,
            };

            PersonManager personManager = this.CreatePersonManagerInstance(
                mockDataCaptureDatabaseAdapter =>
            {
                mockDataCaptureDatabaseAdapter
                .Setup(x => x.ReadPerson(
                           It.IsAny <string>()))
                .Returns(readPersonResult);

                mockDataCaptureDatabaseAdapter
                .Setup(x => x.CreatePerson(
                           It.IsAny <DateTime>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <string>(),
                           It.IsAny <string>()))
                .Returns(createPersonResult);

                mockDataCaptureDatabaseAdapter
                .Setup(x => x.CreateContactDetail(
                           It.IsAny <long>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <string>(),
                           It.IsAny <DateTime?>()))
                .Returns(createContactDetailResult);

                mockDataCaptureDatabaseAdapter
                .Setup(x => x.CreateConsent(
                           It.IsAny <long>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <bool?>()))
                .Returns(createConsentResult);

                mockDataCaptureDatabaseAdapter
                .Setup(x => x.CreateCookie(
                           It.IsAny <long>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <string>()))
                .Returns(createCookieResult);

                mockDataCaptureDatabaseAdapter
                .Setup(x => x.CreateRoute(
                           It.IsAny <long>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <DateTime>(),
                           It.IsAny <string>()))
                .Returns(createRouteResult);
            });

            Person person = new Person()
            {
                Consent = new Consent()
                {
                    GdprConsentDeclared = DateTime.Parse("2018-11-19 08:30:21"),
                    GdprConsentGiven    = true,
                },
                Cookie = new Cookie()
                {
                    Captured         = DateTime.Parse("2018-11-19 08:31:11"),
                    CookieIdentifier = "ABC0123456789",
                },
                Route = new Route()
                {
                    Captured        = DateTime.Parse("2018-11-19 08:29:03"),
                    RouteIdentifier = "ZYX9876543210",
                },
                ContactDetail = new ContactDetail()
                {
                    Captured     = DateTime.Parse("2018-11-18 08:30:21"),
                    EmailAddress = "*****@*****.**",
                    EmailVerificationCompletion = DateTime.Parse("2018-11-18 13:00:23"),
                },
                Enrolled  = DateTime.Parse("2018-11-18 08:30:20"),
                FirstName = "Joe",
                LastName  = "Bloggs",
            };

            PersonRecordExistsAlreadyException thrownException = null;

            // Act
            try
            {
                personManager.Create(person);
            }
            catch (PersonRecordExistsAlreadyException personRecordExistsAlreadyException)
            {
                thrownException = personRecordExistsAlreadyException;
            }

            // Assert
            Assert.IsNull(thrownException);
        }