Exemple #1
0
        public void Should_Fail_With_Invalid_Location()
        {
            var context = GetDbContext();

            var location = Guid.NewGuid();

            context.Locations.Add(new Location {
                Id = location, Name = "Location In Db"
            });
            context.SaveChanges();

            context.Rooms.Add(new Room {
                Id = location, Name = "RL Room", LocationId = location
            });
            context.SaveChanges();

            var locationIdNotInDb = Guid.NewGuid();
            //act

            var sut = new List.Handler(context, _mapper);
            var ex  = Assert.ThrowsAsync <RestException>(() => sut.Handle(new List.Query(locationIdNotInDb), CancellationToken.None));

            var thrownError   = ex.Result.Errors.ToString();
            var expectedError = (new { location = "Location not found" }).ToString();

            Assert.Equal(expectedError, thrownError);
        }
Exemple #2
0
        public void Should_Throw_Exception_On_Invalid_Modality()
        {
            var context = GetDbContext();

            var modalityId = Guid.NewGuid();

            context.Modalities.Add(new Domain.Modality {
                Id = modalityId, Name = "Test Modality"
            });
            context.SaveChanges();

            var licenseId = Guid.NewGuid();

            context.Licenses.Add(new Domain.License {
                Id = licenseId, Name = "Test License", DisplayName = "TL", ModalityId = modalityId
            });

            var sut = new List.Handler(context, _mapper);

            var nonExistingModalityId = Guid.NewGuid();
            var ex = Assert.ThrowsAsync <RestException>(() => sut.Handle(new List.Query(nonExistingModalityId), CancellationToken.None));

            var thrownError   = ex.Result.Errors.ToString();
            var expectedError = (new { modality = "Modality not found" }).ToString();

            Assert.Equal(expectedError, thrownError);
        }
Exemple #3
0
        public void Should_Not_Return_Unrequested_Modality_Licenses()
        {
            var context = GetDbContext();


            var modalityId1 = Guid.NewGuid();
            var modalityId2 = Guid.NewGuid();

            context.Modalities.Add(new Domain.Modality {
                Id = modalityId1, Name = "Requested Modality"
            });
            context.Modalities.Add(new Domain.Modality {
                Id = modalityId2, Name = "Unrequested Modality"
            });
            context.SaveChanges();

            context.Licenses.Add(new Domain.License {
                Id = Guid.NewGuid(), Name = "RM License", DisplayName = "RL", ModalityId = modalityId1
            });
            context.Licenses.Add(new Domain.License {
                Id = Guid.NewGuid(), Name = "UM License", DisplayName = "UL", ModalityId = modalityId2
            });
            context.SaveChanges();

            var sut           = new List.Handler(context, _mapper);
            var result        = sut.Handle(new List.Query(modalityId1), CancellationToken.None).Result;
            var licenseExists = result.Any(x => x.Name == "UM License");

            Assert.Single(result);
            Assert.False(licenseExists);
        }
Exemple #4
0
        public void ReturnListOfAllActivities()
        {
            var options = new DbContextOptionsBuilder <DataContext>()
                          .UseInMemoryDatabase(databaseName: "Return_list_of_values")
                          .Options;

            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });
            var mapper = mockMapper.CreateMapper();

            using (var context = new DataContext(options))
            {
                context.Activities.Add(new Activity {
                    Id = 1, Title = "Test Activity 1"
                });
                context.Activities.Add(new Activity {
                    Id = 2, Title = "Test Activity 2"
                });
                context.SaveChanges();
            }

            // use clean instance of context to run the test
            using (var context = new DataContext(options))
            {
                var sut    = new List.Handler(context, mapper);
                var result = sut.Handle(new List.Query(null, null, null, null), CancellationToken.None).Result;

                Assert.Equal(2, result.ActivityCount);
                Assert.Equal("Test Activity 1", result.Activities[0].Title);
            }
        }
Exemple #5
0
        public void Should_List_Licenses_By_Requested_Modality()
        {
            var context = GetDbContext();


            var modalityId = Guid.NewGuid();

            context.Modalities.Add(new Domain.Modality {
                Id = modalityId, Name = "Test Modality 1 "
            });
            context.SaveChanges();

            context.Licenses.Add(new Domain.License {
                Id = Guid.NewGuid(), Name = "Test License", DisplayName = "TL", ModalityId = modalityId
            });
            context.Licenses.Add(new Domain.License {
                Id = Guid.NewGuid(), Name = "Test License 2", DisplayName = "TL2", ModalityId = modalityId
            });
            context.SaveChanges();

            var sut = new List.Handler(context, _mapper);

            var result = sut.Handle(new List.Query(modalityId), CancellationToken.None).Result;

            var licenseExists = result.Any(x => x.Name == "Test License");

            Assert.Equal(2, result.Count);
            Assert.True(licenseExists);
        }
Exemple #6
0
            public async Task <List <AppActivity> > Handle(Command request, CancellationToken cancellationToken)
            {
                var exists = await _context.SearchActivities.FirstOrDefaultAsync(sa => sa.Input == request.UserInput && sa.UserVisitorId == request.UserVisitorId && sa.UserHostId == request.UserHostId);

                if (exists != null)
                {
                    exists.DateTimeAccessed = DateTime.Now;
                }
                else
                {
                    var newInput = new SearchActivities
                    {
                        Id = Guid.NewGuid(),
                        DateTimeAccessed = DateTime.Now,
                        UserHostId       = request.UserHostId,
                        UserVisitorId    = request.UserVisitorId,
                        Input            = request.UserInput
                    };
                    _context.SearchActivities.Add(newInput);
                }

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    var handler = new List.Handler(_context);
                    return(await handler.Handle(new List.Command {
                        Id = request.UserHostId.ToString(), MatchString = request.UserInput
                    }, cancellationToken));
                }
                throw new Exception("Error saving input activities to db");
            }
Exemple #7
0
        public void Should_Not_Return_Unrequested_Location_Rooms()
        {
            var context = GetDbContext();

            var requestedLocation   = Guid.NewGuid();
            var unrequestedLocation = Guid.NewGuid();

            context.Locations.Add(new Location {
                Id = requestedLocation, Name = "Requested Location"
            });
            context.Locations.Add(new Location {
                Id = unrequestedLocation, Name = "Unrequested Location"
            });
            context.SaveChanges();

            context.Rooms.Add(new Room {
                Id = Guid.NewGuid(), Name = "RL Room", LocationId = requestedLocation
            });
            context.Rooms.Add(new Room {
                Id = Guid.NewGuid(), Name = "UL Room", LocationId = unrequestedLocation
            });
            context.SaveChanges();

            var sut        = new List.Handler(context, _mapper);
            var result     = sut.Handle(new List.Query(requestedLocation), CancellationToken.None).Result;
            var roomExists = result.Any(x => x.Name == "UL Room");

            Assert.Single(result);
            Assert.False(roomExists);
        }
Exemple #8
0
        public void Should_List_Rooms_In_Location()
        {
            //arrange

            var context = GetDbContext();

            var locationId1 = Guid.NewGuid();

            context.Locations.Add(new Location {
                Id = locationId1, Name = "Location 1"
            });
            context.SaveChanges();


            context.Rooms.Add(new Room {
                Id = Guid.NewGuid(), Name = "Test Room 1", LocationId = locationId1
            });
            context.Rooms.Add(new Room {
                Id = Guid.NewGuid(), Name = "Test Room 2", LocationId = locationId1
            });
            context.SaveChanges();

            //act
            var sut    = new List.Handler(context, _mapper);
            var result = sut.Handle(new List.Query(locationId1), CancellationToken.None).Result;

            var roomInLocation = result.Any(x => x.Name == "Test Room 1");

            Assert.Equal(2, result.Count);
            Assert.True(roomInLocation);
        }
Exemple #9
0
        public void Should_List_Modalities()
        {
            var context = GetDbContext();

            context.Modalities.Add(new Modality
            {
                Id          = Guid.NewGuid(),
                Name        = "Modality 1",
                DisplayName = "M1"
            });

            context.Modalities.Add(new Modality
            {
                Id          = Guid.NewGuid(),
                Name        = "Modality 2",
                DisplayName = "M2"
            });

            context.SaveChanges();

            var sut = new List.Handler(context);

            var result = sut.Handle(new List.Query(), CancellationToken.None).Result;

            Assert.Equal(2, result.Count);
            Assert.Equal("Modality 1", result[0].Name);
            Assert.Equal("M2", result[1].DisplayName);
        }
        public async Task ShouldGetTheListOfActivities()
        {
            int? limit   = 10;
            int? offset  = 0;
            bool isGoing = true;
            bool isHost  = false;
            var  query   = new List.Query(limit, offset, isGoing, isHost, null);
            var  result  = await _sut.Handle(query, new System.Threading.CancellationToken(false));

            Assert.NotNull(result);
        }
Exemple #11
0
        public void Should_Fail_Without_Date()
        {
            var sut = new List.Handler(context, _mapper);

            var ex = Assert.ThrowsAsync <RestException>(() => sut.Handle(new List.Query(filterDate: null, filterLicense: null, filterLocation: null, filterModality: null, filterTechnologist: null, monthFlag: null), CancellationToken.None));

            var thrownError   = ex.Result.Errors.ToString();
            var expectedError = (new { error = "Invalid Date" }).ToString();

            Assert.Equal(expectedError, thrownError);
        }
Exemple #12
0
        public void Should_Return_CompanyList()
        {
            var context = GetDbContext();

            var sut = new List.Handler(context);

            var resultString = sut.Handle(new List.Query(), CancellationToken.None).Result;

            Assert.Equal("Apple Inc", resultString[0].Name);
            Assert.Equal("NASDAQ", resultString[0].Exchange);
            Assert.Equal("AAPL", resultString[0].Ticker);
            Assert.Equal("US03738831005", resultString[0].Isin);
            Assert.Equal("http://www.apple.com", resultString[0].Website);
        }
        public async Task Handle_ListAsync_ReturnsAllTrails()
        {
            //Arrange
            trailServiceMock.Setup(x => x.ListAsync()).ReturnsAsync(TrailsMockData.TrailListMock);

            var request           = new List.Query();
            var cancellationToken = new CancellationToken();

            //Act
            List <Trail> trails = await listHandler.Handle(request, cancellationToken);

            //Assert
            trailServiceMock.Verify(x => x.ListAsync(), Times.Once);
            Assert.IsType <List <Trail> >(trails);
        }
        public async Task ShouldReturnAllProductsInDb()
        {
            using (var context = GetDbContext())
            {
                //arrange
                InitProductsTable(context);
                var command = new List.Query();
                var handler = new List.Handler(context, GetMapper());

                //act
                var products = await handler.Handle(command, (new CancellationTokenSource()).Token);

                //assert
                Assert.IsTrue(products.Count == 3);
            }
        }
Exemple #15
0
        public void Should_List_Only_Query_Matching_Shifts()
        {
            var shiftRelatedIds = Create_Shift_For_List_Tests_And_Return_Ids();

            var date = DateTime.Now;

            context.Shifts.Add(new Domain.Shift
            {
                Id             = Guid.NewGuid(),
                Start          = date,
                End            = date.AddHours(8),
                TechnologistId = shiftRelatedIds.TechnologistId1,
                ModalityId     = shiftRelatedIds.ModalityId,
                LicenseId      = shiftRelatedIds.LicenseId1,
                LocationId     = shiftRelatedIds.LocationId,
                RoomId         = shiftRelatedIds.RoomId
            });

            context.Shifts.Add(new Domain.Shift
            {
                Id             = Guid.NewGuid(),
                Start          = date,
                End            = date.AddHours(8),
                TechnologistId = shiftRelatedIds.TechnologistId2,
                ModalityId     = shiftRelatedIds.ModalityId,
                LicenseId      = shiftRelatedIds.LicenseId1,
                LocationId     = shiftRelatedIds.LocationId,
                RoomId         = shiftRelatedIds.RoomId
            });

            context.SaveChanges();

            var sut = new List.Handler(context, _mapper);

            var result = sut.Handle(new List.Query(filterDate: date, filterLicense: null, filterLocation: null, filterModality: null, filterTechnologist: shiftRelatedIds.TechnologistId1, monthFlag: null), CancellationToken.None).Result;

            Assert.Single(result);
            Assert.Equal(shiftRelatedIds.TechnologistId1, result[0].TechnologistId);
        }
        public async Task GetBrands()
        {
            var dbContenxt = await GetDatabaseContext();

            // var brandvms = new List<BrandVm>();
            var mapper = new Mock <IMapper>();

            mapper.Setup(m => m.Map <List <Brand>, List <BrandVm> >(It.IsAny <List <Brand> >()))
            .Returns((List <Brand> src) =>
                     src.Select(x => new BrandVm {
                Id = x.Id, Name = x.Name
            })
                     .ToList());

            var query = new List.Query();

            var handler = new List.Handler(dbContenxt, mapper.Object);

            var result = handler.Handle(query, new CancellationToken());

            var actionResult = Assert.IsType <List <BrandVm> >(result.Result.Value);

            Assert.NotEmpty(actionResult);
        }
Exemple #17
0
        public void Should_List_Technologists()
        {
            var context     = GetDbContext();
            var modalityId1 = Guid.NewGuid();
            var modalityId2 = Guid.NewGuid();

            context.Modalities.Add(new Domain.Modality {
                Id = modalityId1, Name = "Test Modality 1", DisplayName = "TM1"
            });
            context.Modalities.Add(new Domain.Modality {
                Id = modalityId2, Name = "Test Modality 2", DisplayName = "TM2"
            });
            context.SaveChanges();

            var technologistId1 = Guid.NewGuid();
            var technologistId2 = Guid.NewGuid();
            var technologistId3 = Guid.NewGuid();

            //two technologists with same modality
            context.Technologists.Add(new Domain.Technologist
            {
                Id         = technologistId1,
                Name       = "Technologist 1",
                ModalityId = modalityId1,
                Initial    = "T1"
            });


            context.Technologists.Add(new Domain.Technologist
            {
                Id         = technologistId2,
                Name       = "Technologist 2",
                ModalityId = modalityId1,
                Initial    = "T2"
            });

            //one technologist with a different modality

            context.Technologists.Add(new Domain.Technologist
            {
                Id         = technologistId3,
                Name       = "Technologist 3",
                ModalityId = modalityId2,
                Initial    = "T3"
            });



            context.SaveChanges();

            var sut = new List.Handler(context, _mapper);

            var result = sut.Handle(new List.Query(modalityId1), CancellationToken.None).Result;

            var technologistExists       = result.Any(x => x.Name == "Technologist 1");
            var technologistDoesNotExist = result.Any(x => x.Name == "Technologist 3");

            Assert.Equal(2, result.Count);
            Assert.True(technologistExists);
            Assert.False(technologistDoesNotExist);
        }