public async Task GetByIdShouldWorkCorretly()
        {
            AutoMapperConfig.RegisterMappings(typeof(VisualisePropertiesViewModel).Assembly);

            var db       = GetDatabase();
            var property = new Property()
            {
                Id   = 1,
                Name = "Name",
            };
            var property2 = new Property()
            {
                Id   = 2,
                Name = "Name",
            };

            var propertiesRepository = new EfDeletableEntityRepository <Property>(db);

            var service = new PropertiesService(propertiesRepository);

            await db.Properties.AddAsync(property);

            await db.SaveChangesAsync();

            var lol = service.GetById <VisualisePropertiesViewModel>(1);

            Assert.Equal(1, lol.Id);
        }
Example #2
0
        public async Task GetByIdShouldReturnTheCorrectProperty()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "GetByIdPropertiesTestDb").Options;

            using var dbContext = new ApplicationDbContext(options);

            var propertyId   = 5;
            var propertyName = $"Property with ID {propertyId}";

            var manager = new ApplicationUser()
            {
                UserName = "******",
            };

            var tenant = new Tenant()
            {
                Name = "Test tenant",
            };

            dbContext.Properties.Add(new Property()
            {
                Id         = propertyId,
                Name       = propertyName,
                Type       = PMStudio.Data.Models.Enum.PropertyType.Residential,
                Address    = "Kings Lynn",
                Manager    = manager,
                Owner      = "Test owner",
                Tenant     = tenant,
                ModifiedOn = DateTime.Now.AddDays(+1),
                Size       = 500,
            });
            await dbContext.SaveChangesAsync();

            using var propertyRepository = new EfDeletableEntityRepository <Property>(dbContext);
            var propertiesService = new PropertiesService(propertyRepository);
            var property          = propertiesService.GetById <SinglePropertyViewModel>(propertyId);

            Assert.Equal(propertyName, property.Name);
        }