/// <summary>
        /// Modifies a dive log entry
        /// </summary>
        /// <param name="dive">The dive log entry to save</param>
        public async Task ModifyDiveLogEntryAsync(DiveLogEntryDto dive)
        {
            ValidateDiveLogArgument(dive);
            Verify.RaiseWhenFailed();

            using (var ctx = DataAccessFactory.CreateContext <IDiveLogDataAccessOperations>())
            {
                var diveRecord = await ctx.GetDiveLogByIdAsync(dive.Id);

                if (diveRecord == null)
                {
                    throw new DiveNotFoundException(dive.Id);
                }

                if (diveRecord.UserId != ServicedUserId)
                {
                    throw new NoPermissionToDiveLogException(diveRecord.Id, ServicedUserId, diveRecord.UserId);
                }

                diveRecord.Date       = dive.Date;
                diveRecord.DiveSite   = dive.DiveSite;
                diveRecord.Location   = dive.Location;
                diveRecord.MaxDepth   = dive.MaxDepth;
                diveRecord.BottomTime = dive.BottomTime;
                diveRecord.Comment    = dive.Comment;
                await ctx.UpdateDiveLogEntryAsync(diveRecord);
            }
        }
Example #2
0
        public async Task ModifyDiveLogEntryWorksAsExpected()
        {
            // --- Arrange
            var service = HttpServiceFactory.CreateService <IDiveLogService>();
            var dive    = new DiveLogEntryDto
            {
                Date       = new DateTime(2008, 6, 7),
                DiveSite   = "Gotta Abu Ramada",
                Location   = "Hurghada, Egypt",
                MaxDepth   = 22.6M,
                BottomTime = 54,
                Comment    = "It was a great dive"
            };
            var id = await service.RegisterDiveLogEntryAsync(dive);

            // --- Act
            dive.Id         = id;
            dive.BottomTime = 102;
            dive.Comment    = "It was a long dive";
            await service.ModifyDiveLogEntryAsync(dive);

            // --- Assert
            var diveback = await service.GetDiveByIdAsync(id);

            diveback.Id.ShouldBeGreaterThan(0);
            diveback.Date.ShouldEqual(dive.Date);
            diveback.DiveSite.ShouldEqual(dive.DiveSite);
            diveback.Location.ShouldEqual(dive.Location);
            diveback.MaxDepth.ShouldEqual(dive.MaxDepth);
            diveback.BottomTime.ShouldEqual(dive.BottomTime);
            diveback.Comment.ShouldEqual(dive.Comment);
        }
Example #3
0
        public async Task RemoveDiveLogEntryWorksAsExpected()
        {
            // --- Arrange
            var service = HttpServiceFactory.CreateService <IDiveLogService>();
            var dive    = new DiveLogEntryDto
            {
                Date       = new DateTime(2008, 6, 7),
                DiveSite   = "Gotta Abu Ramada",
                Location   = "Hurghada, Egypt",
                MaxDepth   = 22.6M,
                BottomTime = 54,
                Comment    = "It was a great dive"
            };
            var id = await service.RegisterDiveLogEntryAsync(dive);

            // --- Act
            var diveBack1 = await service.GetDiveByIdAsync(id);

            await service.RemoveDiveLogEntryAsync(id);

            var notFound = false;

            try
            {
                await service.GetDiveByIdAsync(id);
            }
            catch (DiveNotFoundException)
            {
                notFound = true;
            }

            // --- Assert
            diveBack1.ShouldNotBeNull();
            notFound.ShouldBeTrue();
        }
Example #4
0
        public async Task ModifyDiveLogEntryFailsWithTooHighBottomTime()
        {
            // --- Arrange
            var service = HttpServiceFactory.CreateService <IDiveLogService>();
            var dive    = new DiveLogEntryDto
            {
                Date       = new DateTime(2008, 6, 7),
                DiveSite   = "Gotta Abu Ramada",
                Location   = "Hurghada, Egypt",
                MaxDepth   = 22.6M,
                BottomTime = 481
            };

            // --- Act
            try
            {
                await service.ModifyDiveLogEntryAsync(dive);
            }
            catch (ArgumentValidationException ex)
            {
                ex.Notifications.Items.ShouldHaveCountOf(1);
                ex.Notifications.Items[0].Target.ShouldEqual("dive.BottomTime");
                ex.Notifications.Items[0].Code.ShouldEqual(ValidationCodes.OUT_OF_RANGE);
                return;
            }
            Assert.Fail("ArgumentValidationException expected.");
        }
Example #5
0
        public async Task ModifyDiveLogEntryFailsWithNullLocation()
        {
            // --- Arrange
            var service = HttpServiceFactory.CreateService <IDiveLogService>();
            var dive    = new DiveLogEntryDto
            {
                Date       = new DateTime(2008, 6, 7),
                DiveSite   = "Gotta Abu Ramada",
                Location   = null,
                MaxDepth   = 22.6M,
                BottomTime = 54
            };

            // --- Act
            try
            {
                await service.ModifyDiveLogEntryAsync(dive);
            }
            catch (ArgumentValidationException ex)
            {
                ex.Notifications.Items.ShouldHaveCountOf(1);
                ex.Notifications.Items[0].Target.ShouldEqual("dive.Location");
                ex.Notifications.Items[0].Code.ShouldEqual(ValidationCodes.NULL_NOT_ALLOWED);
                return;
            }
            Assert.Fail("ArgumentValidationException expected.");
        }
Example #6
0
        public async Task RegisterDiveLogEntryFailsWithPresetId()
        {
            // --- Arrange
            var service = HttpServiceFactory.CreateService <IDiveLogService>();
            var dive    = new DiveLogEntryDto
            {
                Id         = 123,
                Date       = new DateTime(2008, 6, 7),
                DiveSite   = "Gotta Abu Ramada",
                Location   = "Hurghada, Egypt",
                MaxDepth   = 22.6M,
                BottomTime = 54
            };

            // --- Act
            try
            {
                await service.RegisterDiveLogEntryAsync(dive);
            }
            catch (ArgumentValidationException ex)
            {
                ex.Notifications.Items.ShouldHaveCountOf(1);
                ex.Notifications.Items[0].Target.ShouldEqual("dive.Id");
                ex.Notifications.Items[0].Code.ShouldEqual(ValidationCodes.VALIDATION_FAILS);
                return;
            }
            Assert.Fail("ArgumentValidationException expected.");
        }
        /// <summary>
        /// Checks whether arguments are valid
        /// </summary>
        private void ValidateDiveLogArgument(DiveLogEntryDto dive)
        {
            Verify.NotNull(dive, "dive");
            Verify.RaiseWhenFailed();

            Verify.NotNullOrEmpty(dive.DiveSite, "dive.DiveSite");
            Verify.NotNullOrEmpty(dive.Location, "dive.Location");
            Verify.IsInRange(dive.MaxDepth, 0, 300, "dive.MaxDepth");
            Verify.IsInRange(dive.BottomTime, 0, 480, "dive.BottomTime");
        }
Example #8
0
        public async Task ModifyDiveLogEntryFailsWithUnknownDive()
        {
            // --- Arrange
            var service = HttpServiceFactory.CreateService <IDiveLogService>();
            var dive    = new DiveLogEntryDto
            {
                Id         = -1,
                Date       = new DateTime(2008, 6, 7),
                DiveSite   = "Gotta Abu Ramada",
                Location   = "Hurghada, Egypt",
                MaxDepth   = 22.6M,
                BottomTime = 54,
                Comment    = "It was a great dive"
            };

            // --- Act
            await service.ModifyDiveLogEntryAsync(dive);
        }
Example #9
0
        public async Task ModifyDiveLogEntryFailsWithAnotherUser()
        {
            // --- Arrange
            const int ANOTHER_USERS_DIVE_ID = 10;
            var       service = HttpServiceFactory.CreateService <IDiveLogService>();
            var       dive    = new DiveLogEntryDto
            {
                Id         = ANOTHER_USERS_DIVE_ID,
                Date       = new DateTime(2008, 6, 7),
                DiveSite   = "Gotta Abu Ramada",
                Location   = "Hurghada, Egypt",
                MaxDepth   = 22.6M,
                BottomTime = 54,
                Comment    = "It was a great dive"
            };

            // --- Act
            await service.ModifyDiveLogEntryAsync(dive);
        }
Example #10
0
        /// <summary>
        /// Registers a new dive log entry
        /// </summary>
        /// <param name="dive">The dive log entry to save</param>
        public async Task <int> RegisterDiveLogEntryAsync(DiveLogEntryDto dive)
        {
            ValidateDiveLogArgument(dive);
            Verify.Require(dive.Id == 0, "dive.Id");
            Verify.RaiseWhenFailed();

            using (var ctx = DataAccessFactory.CreateContext <IDiveLogDataAccessOperations>())
            {
                var diveRecord = new DiveLogRecord
                {
                    UserId     = ServicedUserId,
                    Date       = dive.Date,
                    DiveSite   = dive.DiveSite,
                    Location   = dive.Location,
                    MaxDepth   = dive.MaxDepth,
                    BottomTime = dive.BottomTime,
                    Comment    = dive.Comment
                };
                await ctx.InsertDiveLogEntryAsync(diveRecord);

                return(diveRecord.Id);
            }
        }
Example #11
0
 public async Task ModifyDiveLogEntryAsync(DiveLogEntryDto dive)
 {
     var srvObj = HttpServiceFactory.CreateService <IDiveLogService>();
     await srvObj.ModifyDiveLogEntryAsync(dive);
 }
Example #12
0
        public async Task <int> RegisterDiveLogEntryAsync(DiveLogEntryDto dive)
        {
            var srvObj = HttpServiceFactory.CreateService <IDiveLogService>();

            return(await srvObj.RegisterDiveLogEntryAsync(dive));
        }